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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Need urgent help on SQL Pivot query

Author  Topic 

Tarakeswara_Allu
Starting Member

2 Posts

Posted - 2014-03-06 : 23:56:22
This is how data is in the table.

Column0 Column1 Column2 Column3 Column4 Column 5
2013 NULL NULL NULL NULL NULL
JED Jan Feb Mar Apr May
WT 24 9 11 10 9
L/B 1058 1859 1088 986 1265
AHL 1212 993 1434 1207 1170
DPR 96 61 74 67 77
Lost 333 333 382 331 353
RR 73 66 73 73 70

and it needs to be reorganized as below.

Year Month Station WT LB AHL DPR LOST RR
2013 Jan JED 24 1058 1212 96 333 73
2013 Feb JED 9 1859 993 61 333 66




Tarakeswara Rao Allu

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-03-07 : 00:18:37
refer to http://technet.microsoft.com/en-us/library/ms177410%28v=sql.105%29.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Tarakeswara_Allu
Starting Member

2 Posts

Posted - 2014-03-07 : 00:36:11
quote:
Originally posted by khtan

refer to http://technet.microsoft.com/en-us/library/ms177410%28v=sql.105%29.aspx


KH
[spoiler]Time is always against us[/spoiler]



but here I don't have to perform any aggregate function

Tarakeswara Rao Allu
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-03-07 : 00:37:42
you can use MAX()


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -