Answered by:
UPDATE Statement

Question
-
Hi all when i'm trying to execute the following statement i'm getting an error "incorrect syntax near GO" can anyone please tell me what is wrong?
UPDATE dbo.STG_SPACE
SET DateID = ID
FROM dbo.DIM_TIME
WHERE Date = PK_Date GO
UPDATE STG_SPACE
SET DateID = - 1
WHERE DateID IS NULL
GOThanks
Monday, January 28, 2013 6:45 PM
Answers
-
UPDATE dbo.STG_SPACE SET DateID = ID FROM dbo.DIM_TIME WHERE [DATE] = PK_Date GO UPDATE STG_SPACE SET DateID = - 1 WHERE DateID IS NULL
Looks like you needed a carriage return after your first update. See if this works, or give you a more accurate error messageChuck Pedretti | Magenic – North Region | magenic.com
Monday, January 28, 2013 6:50 PM -
Here is the explaination for why your code didn't work:
http://msdn.microsoft.com/en-us/library/ms188037.aspx
A Transact-SQL statement cannot occupy the same line as a GO command. However, the line can contain comments.
Chuck Pedretti | Magenic – North Region | magenic.com
Monday, January 28, 2013 6:58 PM
All replies
-
UPDATE dbo.STG_SPACE SET DateID = ID FROM dbo.DIM_TIME WHERE [DATE] = PK_Date GO UPDATE STG_SPACE SET DateID = - 1 WHERE DateID IS NULL
Looks like you needed a carriage return after your first update. See if this works, or give you a more accurate error messageChuck Pedretti | Magenic – North Region | magenic.com
Monday, January 28, 2013 6:50 PM -
Here is the explaination for why your code didn't work:
http://msdn.microsoft.com/en-us/library/ms188037.aspx
A Transact-SQL statement cannot occupy the same line as a GO command. However, the line can contain comments.
Chuck Pedretti | Magenic – North Region | magenic.com
Monday, January 28, 2013 6:58 PM -
;WITH mycte AS (SELECT SS.DateID, dt.ID FROM dbo.STG_SPACE ss LEFT JOIN dbo.DIM_TIME dt ON DT.PK_Date = SS.Date) UPDATE mycte SET DateID = CASE WHEN DateID IS NULL THEN -1 ELSE ID END
Monday, January 28, 2013 10:21 PM