Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Student:--------SID Admission--- ------------1 123456789StudentDetails:--------------SID MID Lastname Fname Admission---- ------ --------- --------- ------------1 1 John Denn 1234567891 2 John Camb 123456780Expected output:1, john, Denn , 123456789, 2, john, Camb, 123456780Join condition : Student.SID = StudentDetails.SID
Thanks for your help in advance !
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2014-05-05 : 21:45:33
the expected output is in 8 columns ?KH[spoiler]Time is always against us[/spoiler]
MuralikrishnaVeera
Posting Yak Master
129 Posts
Posted - 2014-05-06 : 06:23:36
If you want the output in one column then use this
SELECT STUFF( (select ', '+CASt(sd.MID as VARCHAR(MAX))+' , '+sd.Lastname+' , '+sd.Fname+' , '+CAST(sd.Admission AS VARCHAR(MAX))FROM Student AS sINNER JOIN StudentDetails AS sdON s.SID =sd.SID FOR XML PATH('')),1,1,'') AS Result
If you want 8 columns output then use DYNAMIC PIVOT---------------Murali KrishnaYou live only once ..If you do it right once is enough.......
sqlfresher2k7
Aged Yak Warrior
623 Posts
Posted - 2014-05-06 : 23:47:22
Thanks Expected output columns is 8.Don't need the commas.Sorry for the confusion
khtan
In (Som, Ni, Yak)
17689 Posts
Posted - 2014-05-07 : 00:53:10
and there will be max 2 MID per 1 SID ?KH[spoiler]Time is always against us[/spoiler]
sqlfresher2k7
Aged Yak Warrior
623 Posts
Posted - 2014-05-07 : 10:56:34
there will more than 2 MID's for 1 SID.I assume max MID could be more than 10..