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 |
|
zez0
Starting Member
24 Posts |
Posted - 2009-10-05 : 04:56:03
|
| first Table-----------------Id Class Name-----------------1 Math2 science3 computersecond table ----------------------------ClassIs Spesefications----------------------------3 1231 1472 369I need query that give me this result RESULT :Math science computer147 369 123zezo |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-05 : 04:57:49
|
are you using SQL 2005 / 2008 ? KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
zez0
Starting Member
24 Posts |
Posted - 2009-10-05 : 05:01:21
|
| SQL 2005zezo |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-10-05 : 05:03:10
|
[code]declare @first Table( [Id] int, [Class Name] varchar(10))insert into @firstselect 1, 'Math' union allselect 2, 'science' union allselect 3, 'computer'declare @second table( [ClassIs] int, [Spesefications] int)insert into @secondselect 3, 123 union allselect 1, 147 union allselect 2, 369-- SQL 2000 / 2005 / 2008select Math = max(case when f.[Class Name] = 'Math' then [Spesefications] end), science = max(case when f.[Class Name] = 'science' then [Spesefications] end), computer = max(case when f.[Class Name] = 'computer' then [Spesefications] end)from @first f inner join @second s on f.Id = s.ClassIs-- SQL 2005 / 2008select *from ( select f.[Class Name], s.[Spesefications] from @first f inner join @second s on f.Id = s.ClassIs ) d pivot ( max([Spesefications]) for [Class Name] in ([Math], [science], [computer]) ) p[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
zez0
Starting Member
24 Posts |
Posted - 2009-10-05 : 05:20:55
|
| Thankszezo |
 |
|
|
|
|
|
|
|