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)
 sql query help sqlserver 2000

Author  Topic 

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2006-10-12 : 16:36:38
Please help me in the writing the query.

I have data in a table below.

id rcode
-- -----
101 A1
102 A1
101 A2
102 A2
113 A2
120 A2
101 A3
102 A3
108 A3
124 A3
102 A4
102 A5
106 A5

I want the output like below:


id A1 A2 A3 A4 A5
--- -- ---- --- --- ---
101 A1 A2 A3 null null
102 A1 A2 A3 A4 A5
106 null null null null A5
108 null null A3 null null
113 null A2 null null null
120 null A2 null null null
124 null null A3 null null

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2006-10-12 : 16:41:58
take a look at GROUP BY and CASE in bol.

SqlSpec - a fast, cheap, and comprehensive data dictionary generator for SQL Server 2000 and 2005 - http://www.elsasoft.org
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-12 : 16:42:01
What you're looking for is a crosstab query, which you do with the PIVOT clause in SQL Server 2005, but in SQL Server 2000 you'll need to code it yourself or read this excellent article and find out how to code it:
http://www.sqlteam.com/item.asp?ItemID=2955
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-13 : 10:14:54
Also refer

http://weblogs.sqlteam.com/jeffs/archive/2005/05.aspx

Madhivanan

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

- Advertisement -