Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I have a Table
SQL
SL, R_ID,  Name, AMT1, AMT2, AMT3, Pos
1     5     ggg   10     60   22   Left
2     5     hhh   44     88   47   Right


I want Output Like this

SQL
LSL, LID,  LName, LAMT1, LAMT2, LAMT3, LPos   SL,   RID,  RName, RAMT1, RAMT2, RAMT3, RPos
1     5     ggg   10     60   22   Left  2     5     hhh   44     88   47   Right


What I have tried:

SQL
SELECT SL, [LSL], [LSL_HEAD], [LAMT], [LCURR], [LPRE], [RSL], [RSL_HEAD], [RAMT], [RCURR], [RPRE]
FROM
	(select SL, R_ID, SL_HEAD, AMT, CURR, PRE, L_SLIDE from FinalAccountDetails f) as st
					
PIVOT
(
	max(R_ID)
FOR
[L_SLIDE]
	IN ([LSL], [LSL_HEAD], [LAMT], [LCURR], [LPRE], [RSL], [RSL_HEAD], [RAMT], [RCURR], [RPRE])
) AS pvt
Posted
Updated 14-Sep-17 14:03pm
v3
Comments
OriginalGriff 14-Sep-17 8:28am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. And we have no idea why the data "combines" in that way - what happens if there are more than two rows in your table? How should they be combined, and on what fields?
Use the "Improve question" widget to edit your question and provide better information.

1 solution

select 
    lsl   = l.SL
  , lid   = l.R_ID
  , lname = l.SL_HEAD
  , lamt1 = l.AMT
  , lamt2 = l.CURR
  , lamt3 = l.PRE
  , lpos  = l.L_SLIDE
  , rsl   = r.SL
  , rid   = r.R_ID
  , rname = r.SL_HEAD
  , ramt1 = r.AMT
  , ramt2 = r.CURR
  , ramt3 = r.PRE
  , rpos  = r.L_SLIDE
from finalaccountdetails l
  inner join finalaccountdetails r
    on l.r_id = r.r_id
   and l.L_SLIDE = 'left'
   and r.L_SLIDE = 'right'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900