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)
 Returning value from query

Author  Topic 

fralo
Posting Yak Master

161 Posts

Posted - 2010-12-21 : 13:50:19
Hi all,

I'm very new with t-sql. I'm trying to simply store the value from a query and am unsure what is wrong with this statement.

I'm getting: 'Incorrect syntax near the keyword 'select'

BEGIN
set @empid = select empid from [eso-cad].empmast.dbo.empmast a
where a.lname =@lname and a.mname = @mname and a.fname = @fname

update test_Concentra
set empid = @empid
where lname = @lname and mname = @mname and fname = @fname

fetch next from emp_cursor into @lname,@fname,@mname
end

Thanks for your help.

Kristen
Test

22859 Posts

Posted - 2010-12-21 : 13:58:50
set SELECT @empid = select empid from [eso-cad].empmast.dbo.empmast a
where a.lname =@lname and a.mname = @mname and a.fname = @fname

Although:

1. Your statement is not ATOMIC so there is opportunity for another process to update the record between your SELECT and UPDATE
2. Using Cursors is slow and not recommended. Use SET-Based logic if possible.
Go to Top of Page

fralo
Posting Yak Master

161 Posts

Posted - 2010-12-21 : 14:05:15
That works. thanks a lot.
Go to Top of Page
   

- Advertisement -