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.
Author |
Topic |
ricky_1605
Starting Member
30 Posts |
Posted - 2010-09-30 : 04:24:16
|
Hi guysI have a table in which data of 3 locations is there in different rows, of a particular date. I am passing date as parameter in the stored procedure. The problem is when i fetch the data, it is displayed in 3 different rows but i want it in a single row. Can anyone help me on this? Nipun Chawla |
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2010-09-30 : 07:57:12
|
Can you give table structure, example data and wanted output? No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-09-30 : 13:04:34
|
group on your date field and use likeSELECT DateField,MAX(CASE WHEN location='1st location' THEN yourdata ELSE NULL END) AS 1stloc,MAX(CASE WHEN location='2nd location' THEN yourdata ELSE NULL END) AS 2ndloc,MAX(CASE WHEN location='3rd location' THEN yourdata ELSE NULL END) AS 3rdlocFROM TableWHERE Date=@YourdateGROUP BY datefield ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
ricky_1605
Starting Member
30 Posts |
Posted - 2010-10-01 : 01:26:33
|
Thanks a ton visakh16. I got the required result. I guess i was using MAX at the wrong place i.e. (only for data) that is why it was asking me to include location in group by clause.Cheers!Nipun Chawla |
 |
|
|
|
|