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 2000 Forums
 SQL Server Development (2000)
 Pivot

Author  Topic 

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 2008-11-17 : 10:07:53

Hi,

I have a table as follows:

RuleID | Reference | Sequence
-----------------------------
1234 Test 1
1234 More 2
1234 other 3
5678 etc.. 1

I would like to display the data a follows:

Rule ID | Ref 1 | Ref 2 | Ref 3 | Ref 4
----------------------------------------
1234 Test More other null
5678 etc.. null null null

How would I do this?

Thanks,
Kabir

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-11-17 : 10:26:12
select RuleID,
max(case when Reference ='Test'or Reference = 'etc..' then Reference else null end)as Ref1,
max(case when Reference ='More' then Reference else null end)as Ref2,
max(case when Reference ='other'then Reference else null end)as Ref3,
max(case........................
from tables
group by RuleID
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-17 : 11:38:19
will reference names be always static?
Go to Top of Page

KabirPatel
Yak Posting Veteran

54 Posts

Posted - 2008-11-17 : 11:41:26

No - afraid not. The control reference value can be anything.

Any other ideas?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-18 : 04:41:15
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -