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 2005 Forums
 Transact-SQL (2005)
 Updating Multiple Values

Author  Topic 

sanjay5219
Posting Yak Master

240 Posts

Posted - 2014-10-08 : 04:19:07
Hi All,

I have one table called std and another is std_sub. Now I have to update subject_detail column of STD table like Math,English

Please suggest

Std_Sub is a below format
std_id,subject
1,Math
1,English
2,Science
2,Math

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2014-10-08 : 08:29:58
[code]
UPDATE s
SET subject_details = stuff(ss.subjects, 1, 1, '')
FROM std s
CROSS APPLY
(
SELECT ',' + subject
FROM Std_Sub x
WHERE x.std_id = s.id
FOR XML PATH('')
) ss (subjects)
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -