Author |
Topic |
sridhar3004
Starting Member
34 Posts |
Posted - 2011-10-12 : 02:57:53
|
I've the following tableName Type Price1 Price2----------------------------ABCD Buy 10 20ABCD Sell 15 25I want the output for ABCD in one line as followsABCD, Buy, 10, 20, Sell, 15, 25Any help will be appreciated.Thanks in advanceSridhar |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-12 : 03:02:13
|
will you have more than two record for the same Name ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
sridhar3004
Starting Member
34 Posts |
Posted - 2011-10-12 : 03:05:40
|
Nope. Only 2 |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-12 : 03:07:22
|
are you trying to export it to csv or something?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
sridhar3004
Starting Member
34 Posts |
Posted - 2011-10-12 : 03:31:15
|
I want this to be displayed on screen |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-12 : 03:34:19
|
as one column or 7 columns ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
sridhar3004
Starting Member
34 Posts |
Posted - 2011-10-12 : 03:43:31
|
as 7 columns |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-10-12 : 03:50:05
|
[code]select [Name], [Type] = max(case when row_no = 1 then [Type] end), [Price1] = max(case when row_no = 1 then [Price1] end), [Price2] = max(case when row_no = 1 then [Price2] end), [Type] = max(case when row_no = 2 then [Type] end), [Price1] = max(case when row_no = 2 then [Price1] end), [Price2] = max(case when row_no = 2 then [Price2] end)from ( select *, row_no = row_number() over (partition by [Name] order by [Type]) from yourtbl ) tgroup by [Name][/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
sridhar3004
Starting Member
34 Posts |
Posted - 2011-10-13 : 08:22:52
|
Thanks guys. It worked.Warm RegardsSridhar |
 |
|
|