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 table A from table b -- Stored Procedure

Author  Topic 

sinjin67
Yak Posting Veteran

53 Posts

Posted - 2009-01-02 : 19:00:17
Having a little trouble with this one.. I am trying to update
Table A from Table B..Here is my basic SP and the error I get
I cant seem to figure what I missed.
Thanks for the help


CREATE PROCEDURE dbo.changeover1

UPDATE label01
us1id = litid,
us1 = lit1a,
email = lit2a,
FROM Label01 INNER JOIN Yak
On label01.us1id = Yak.us1id
WHERE label01.us1id = Yak.us1id

GO

Msg 156, Level 15, State 1, Procedure changeover1, Line 3
Incorrect syntax near the keyword 'UPDATE'.



sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2009-01-02 : 19:47:50
UPDATE label01
set
us1id = litid,
us1 = lit1a,
email = lit2a,
FROM Label01 INNER JOIN Yak
On label01.us1id = Yak.us1id
WHERE label01.us1id = Yak.us1id

Also, although it does no harm, you don't need the where clause because that is already taken care of in the join condition.
Go to Top of Page

sinjin67
Yak Posting Veteran

53 Posts

Posted - 2009-01-02 : 23:42:59
I left the "where" in because I was just not sure..
But at least I got close.

Thanks for the help...I am greatful for the point
in the right direction...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-03 : 06:40:20
i prefer using aliases for tables rather than repeating table names everywhere

UPDATE l
set
us1id = litid,
us1 = lit1a,
email = lit2a,
FROM Label01 l
INNER JOIN Yak y
On l.us1id = y.us1id
Go to Top of Page
   

- Advertisement -