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
 Problems w/ sub select in an update statement

Author  Topic 

crugerenator
Posting Yak Master

126 Posts

Posted - 2008-11-18 : 12:21:48

I'm having problems w/ a sub select in an update statement. The error msg is "Incorrect syntax near the keyworkd 'as'". Is it even possible to do what I'm trying to do?


update Export
set profileID = (select profileID from [Profile] where profileName = @name) as exportID
where storeID = @storeID


Thanks ahead of time, love the quick response I always get on these forums.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-18 : 12:24:12
no need of as. also make sure subquery returns only single value. i didnt understand why you're not relating tables on any field

update Export
set profileID = (select profileID from [Profile] where profileName = @name)
where storeID = @storeID
Go to Top of Page

crugerenator
Posting Yak Master

126 Posts

Posted - 2008-11-18 : 12:28:43
Thanks.

It's kind of a weird setup, I don't need to relate tables. The only reason I need to do the sub select is because this query fires right after an insert query to insert a profile into the profile table. I don't know the profileID unless I find it w/ the profileName that was just inserted (yes, profileName must be unique).
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-18 : 12:36:30
Ok. but atleast make sure subquery returns single value else you might get unexpected results.
Go to Top of Page
   

- Advertisement -