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
 General SQL Server Forums
 New to SQL Server Programming
 Update Column

Author  Topic 

sanjay5219
Posting Yak Master

240 Posts

Posted - 2013-03-27 : 11:26:17
Hi All,
I have two table, I have to update Column Marks In Table1 from Table2 based on marks and unioue column in Roll

Please suggest

Table1
Roll Name Marks
1 A 34,65,89
2 B 80,76
3 C

Table 2
Roll Subject Marks
1 Hindi 34
1 English 65
1 French 89
2 French 80
2 Maths 76

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-27 : 11:40:14
[code]select
t1.roll,
t1.Name,
stuff((
select ',' as [text()],t2.marks as [text()]
from Table2 t2
where t1.roll = t2.roll
for XML path('')),1,1,''
) as marks
from
Table1 t1;[/code]

If you want to update Table1, then this (assuming marks is a character type column in Table1)[code]update t1 set marks =
stuff((
select ',' as [text()],t2.marks as [text()]
from Table2 t2
where t1.roll = t2.roll
for XML path('')),1,1,''
)
from
Table1 t1;[/code]
Go to Top of Page
   

- Advertisement -