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
 set with select statement

Author  Topic 

seekerPoet
Starting Member

4 Posts

Posted - 2012-09-27 : 11:06:09
I am wanting to update a temp table in a sp by the following script:

UPDATE #SalesDetail
SET DriverName = SELECT DriverName FROM EP_Main.vDriver v INNER JOIN #SalesDetail sd
on v.DriverID = sd.DriverID

It errors out at the select

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-27 : 11:10:33
syntax was wrong

it should be


UPDATE sd
SET sd.DriverName = v.DriverName
FROM EP_Main.vDriver v
INNER JOIN #SalesDetail sd
on v.DriverID = sd.DriverID


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

seekerPoet
Starting Member

4 Posts

Posted - 2012-09-27 : 11:30:28
Thank you for such quick response. When I run code against this sp it now errors out saying it can not find EP_Main.vDriver. This is a view so how do you gain data from a view using the script above.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-27 : 11:34:27
is EP_Main your schema name? if not only this is enough

UPDATE sd
SET sd.DriverName = v.DriverName
FROM Driver v
INNER JOIN #SalesDetail sd
on v.DriverID = sd.DriverID


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

seekerPoet
Starting Member

4 Posts

Posted - 2012-09-27 : 11:37:01
EP_Main is one dbase entity of several
Go to Top of Page

seekerPoet
Starting Member

4 Posts

Posted - 2012-09-27 : 11:48:24
solved it. it needed to be EP_Main.dbo.vdriver
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-09-27 : 11:57:22
ok...then that means EP_Main is your database name

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -