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 A RECORD FROM COLUMN VALUES OF OTHER TABLE

Author  Topic 

DURGESH
Posting Yak Master

105 Posts

Posted - 2008-06-10 : 00:03:19
HI ALL,
CAN ANYBODY HELP ME TO SOLVE THE ISSUE
I WANNA UPDATE A RECORD OF ONE TABLE WITH VALUES THAT ARE PRESENT IN A COLUMN OF ANOTHER TABLE
OR

CAN I DO THE SAME USING INSERT QUERY

THANKS IN ADVANCE

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-10 : 00:22:17
UPDATE d
SET d.Field1=s.Fieldn
FROM destinationtable d
INNER JOIN SourceTable s
ON d.LinkingCol=s.LinkingCol

where linking columns are columns by which two tables are related
Go to Top of Page

dreddski
Starting Member

9 Posts

Posted - 2008-06-10 : 12:14:49
hi there Visakh,
I just want to ride on with Durgesh question..

Can you further clarify your code by this example:?
for example: I have two tables "MASTER" and "SLAVE"..both have columns "Tester" and "Handler" in it...

So If I made a transaction on the "MASTER" Table to update the data on "Tester" and "Handler" colums, how can the values of the "tester" and "handler" Data of the "SLAVE" Table be updated using your code? Thanks...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-10 : 12:18:03
UPDATE d
SET d.Tester=s.Tester,
d.Handler=s.Handler
FROM SLAVE d
INNER JOIN MASTER s
ON d.LinkingCol=s.LinkingCol

Linking columns are columns in MASTER & SLAVE by which two tables are related
Go to Top of Page

dreddski
Starting Member

9 Posts

Posted - 2008-06-11 : 12:12:17
hi visakh.. thanks for the reply and I got the idea... but somehow it wont work...

For the first line

Update d, ' is this really the syntax or the d is a variable?

sorry newbie here..thanks!
Go to Top of Page

dreddski
Starting Member

9 Posts

Posted - 2008-06-11 : 12:12:18
hi visakh.. thanks for the reply and I got the idea... but somehow it wont work...

For the first line

Update d, ' is this really the syntax or the d is a variable?

sorry newbie here..thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-11 : 12:21:44
quote:
Originally posted by dreddski

hi visakh.. thanks for the reply and I got the idea... but somehow it wont work...

For the first line

Update d, ' is this really the syntax or the d is a variable?

sorry newbie here..thanks!


d is the alias for table SLAVE UPDATE d suggests SLAVE is to be updated.
Go to Top of Page
   

- Advertisement -