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)
 Update query

Author  Topic 

satish.gorijala
Posting Yak Master

182 Posts

Posted - 2009-07-02 : 05:30:52
Hi, i need an update query for below requirement.

Table "Tbl_NCVoters" with following data

Name Culture
satish
ranjit
hemanth

Table "Tbl_LastName" with following data
Name Culture
satish INDI
himesh RUSS
satish GERM
yogesh ENGL
hemanth RUSS

Need output as follows

Name Culture
satish INDI,GERM
ranjit null
hemanth RUSS

I wrote an update query for this. but i need an update query to append the culture for the same name with comma. My query updates only one value. my query is below

Update t2 Set t2.Culture = t1.Culture From Tbl_NCVoters As t2
INNER JOIN TBL_LastName As t1 on t2.Name = t1.Name

G. Satish

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-02 : 05:42:01
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

satish.gorijala
Posting Yak Master

182 Posts

Posted - 2009-07-02 : 06:09:35
Can you give query related to my requirement. I am not able to understand that thing which u provided in the link. I am beginner to sqlserver.

quote:
Originally posted by madhivanan

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81254

Madhivanan

Failing to plan is Planning to fail



G. Satish
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-07-02 : 06:10:11
Update t2 Set
t2.Culture = t1.Culture
From Tbl_NCVoters As t2
INNER JOIN (select distinct Name, stuff((select ','+Culture from TBL_LastName where empid = t.empid for xml path('')),1,1,'')as culture
from TBL_LastName t
) As t1 on t2.Name = t1.Name
Go to Top of Page

satish.gorijala
Posting Yak Master

182 Posts

Posted - 2009-07-02 : 06:33:08

Thank you.. Its work perfect
quote:
Originally posted by bklr

Update t2 Set
t2.Culture = t1.Culture
From Tbl_NCVoters As t2
INNER JOIN (select distinct Name, stuff((select ','+Culture from TBL_LastName where empid = t.empid for xml path('')),1,1,'')as culture
from TBL_LastName t
) As t1 on t2.Name = t1.Name




G. Satish
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-07-02 : 07:56:30
quote:
Originally posted by satish.gorijala


Thank you.. Its work perfect
quote:
Originally posted by bklr

Update t2 Set
t2.Culture = t1.Culture
From Tbl_NCVoters As t2
INNER JOIN (select distinct Name, stuff((select ','+Culture from TBL_LastName where empid = t.empid for xml path('')),1,1,'')as culture
from TBL_LastName t
) As t1 on t2.Name = t1.Name




G. Satish


welcome
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-02 : 11:43:37
also see

http://www.projectdmx.com/tsql/rowconcatenate.aspx
Go to Top of Page
   

- Advertisement -