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 |
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 RollPlease suggestTable1 Roll Name Marks1 A 34,65,892 B 80,763 C Table 2 Roll Subject Marks1 Hindi 341 English 651 French 892 French 802 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 marksfrom 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] |
|
|
|
|
|
|
|