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 |
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2009-08-08 : 08:57:32
|
Hi all, I have one table with structure and instances under:CREATE TABLE Course( S_No int, course nvarchar(25) ) INSERT CourseSELECT 1,'math 1' UNION ALLSELECT 1,'phisisc 1' UNION ALLSELECT 2,'math 1' UNION ALLSELECT 3,'culture' UNION ALLSELECT 3,'history' UNION ALLSELECT 3,'art'S_No course----------- -------------------------1 math 11 phisisc 12 math 13 culture3 history3 art Then I want to get the result similar to:S_No Course1 Course2 Course3----------- ------------------------- ------------------------- -------------------------1 math 1 phisisc 1 2 math 1 3 art culture history please create a query without using RANKING FUNCTION and PIVOT. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2009-08-08 : 09:11:17
|
In fact this topic is the same that topic.I want to achieve this result to SQL Server 2000. |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-08-08 : 14:59:38
|
[code]Declare @T Table ( S_No int, course nvarchar(25) ) INSERT @TSELECT 1,'math 1' UNION ALLSELECT 1,'phisisc 1' UNION ALLSELECT 2,'math 1' UNION ALLSELECT 3,'culture' UNION ALLSELECT 3,'history' UNION ALLSELECT 3,'art'--select * from @TSelect S_No,Max(Case When S_No in (1,2,3) and course in('math 1','art') then course else '' end) as Course1,Max(Case When S_No in (1,2,3) and course in('phisisc 1','culture') then course else '' end) as Course2,Max(Case When S_No in (1,2,3) and course = 'history' then course else '' end) as Course3from @TGroup by S_No[/code] |
|
|
ms65g
Constraint Violating Yak Guru
497 Posts |
Posted - 2009-08-09 : 03:53:50
|
thank you sodeep.but imagin I changed the data then what will be result?It is easier that use this query!select s_no=1, [course1]='math 1', [course2]='phisisc 1', [course3]='' unionselect 2,'math 1', '', ''unionselect 3,'art', 'culture', 'history' |
|
|
|
|
|
|
|