Link to home
Start Free TrialLog in
Avatar of PeterBaileyUk
PeterBaileyUk

asked on

sql update

I am trying to create an update query where the tw.StrCommon field is updated to the result of the IIF but It says it cannot bind the tw.StrCommon.

The query as a select works fine.

CREATE PROCEDURE [dbo].[usp_UpdateStrCommon]

AS
BEGIN
UPDATE dbo.TblWords
SET tw.StrCommon= IIF(tsdl.StrShort IS NULL, tw.StrShort, tsdl.StrCommon)
FROM TblWords tw LEFT JOIN TblShortDescLink tsdl ON tsdl.StrShort = tw.StrShort


END

Open in new window


the select query which works fine
SELECT tw.strshort,  IIF(tsdl.StrShort IS NULL, tw.StrShort, tsdl.StrCommon) AS StrTemp
FROM TblWords tw LEFT JOIN TblShortDescLink tsdl ON tsdl.StrShort = tw.StrShort

Open in new window

Avatar of Lokesh B R
Lokesh B R
Flag of India image

Hi,

try this

UPDATE q 
SET q.StrCommon =  SELECT IIF(tsdl.StrShort IS NULL, tw.StrShort, tsdl.StrCommon)
FROM TblWords tw LEFT JOIN TblShortDescLink tsdl ON tsdl.StrShort = tw.StrShort

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial