Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Query Result

Author  Topic 

sanjay5219
Posting Yak Master

240 Posts

Posted - 2010-12-29 : 12:21:04
Hi All,

This is my table details.

Please help
Parameter Week_No Actual_Score
P1 1 99
P2 2 50
P3 3 65%
P4 4 37%

Now i want the output like this in SQL

Param W1 W2 W3 W4
P1 99
P2 50
P3 65%
P4 37%


nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-12-29 : 20:37:07
looks like
select param=parameter, W1=actual_score, W2='', W3='', W4=''
from tbl


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2010-12-29 : 20:39:28
ah - maybe it's lost the spaces when you posted

select param=parameter
,W1=case when weekno=1 then actual_score else '' end
,W2=case when weekno=2 then actual_score else '' end
,W3=case when weekno=3 then actual_score else '' end
,W4=case when weekno=4 then actual_score else '' end
from tbl


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -