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 |
|
the1gadget
Yak Posting Veteran
55 Posts |
Posted - 2006-04-21 : 06:47:29
|
| Hi AllI am doing a query Select top 5 CatId from Fubar where id = 1234 order by CatIdAnd I get a result likeCatID----- 1 6 12 13 100But I want the result back as on row likeCatID_1 CatID_2 CatID_3 CatID_4 CatID_5------- ------- ------- ------- ------- 1 6 12 13 100The other problem is that there may not be 5 results so I would want to get the results back likeCatID_1 CatID_2 CatID_3 CatID_4 CatID_5------- ------- ------- ------- ------- 1 6 12 13 <NULL>orCatID_1 CatID_2 CatID_3 CatID_4 CatID_5------- ------- ------- ------- ------- 1 6 12 13 Any one help ?-- David |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
the1gadget
Yak Posting Veteran
55 Posts |
Posted - 2006-04-21 : 07:36:00
|
| Hi MadhivananMust be me being stupid but I can not see how this takes a result set and rotates it. -- David |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-04-21 : 08:52:27
|
| declare @t table(catid int)insert into @tselect 1 union all select 6 union all select 12 union allselect 13 union all select 100declare @s varchar(8000)select @s=Coalesce(@s+',','')+cast(catId as varchar(10)) from @texec('Select '+ @s)MadhivananFailing to plan is Planning to fail |
 |
|
|
the1gadget
Yak Posting Veteran
55 Posts |
Posted - 2006-04-21 : 09:29:33
|
| Hi MadhivananNow I see. Thanks |
 |
|
|
|
|
|