November 15, 2011 at 7:36 am
I have the following MERGE statement:
MERGE ININ_DataSync_Shadow AS target
USING (SELECT i.IndivID FROM dbo.Individual) AS SOURCE (IndivID)
ON (TARGET.ObjectID = SOURCE.IndivID AND TARGET.ObjectType = 602)
WHEN MATCHED THEN
UPDATE SET SyncStatus = 'N', Operation = 'U', ModifiedBy = 'dbo', ModifiedDate = GETDATE()
WHEN NOT MATCHED THEN
INSERT (ObjectType, ObjectID, Operation, SyncStatus, CreatedBy, CreatedDate)
VALUES (602, SOURCE.IndivID, 'I', 'N', 'dbo', GETDATE())
And when I attempt to run it, I get the following errors:
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'AS'.
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'AS'.
I've tried adding dbo.tablename for my TARGET and SOURCE, aliasing columns, Google and I cannot seem to get this figured out. This is my first attempt using a MERGE statement, so any and all help will be greatly appreciated.
November 15, 2011 at 8:26 am
It looks like you're trying to run this on a SQL 2005 server. MERGE was introduced in SQL 2008, so it will produce those exact errors when run on a SQL 2005 server.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 15, 2011 at 8:34 am
You are 100% correct, I should of known that.
Thanks
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply