Question

This merge script i'm writing isn't compiling and I believe I have the correct syntax.

MERGE into MyTable ct_current
USING (SELECT '0%' as Description, '0' as ShareAmount) ct_value
    ON ct_current.ShareAmount = ct_value.ShareAmount
WHEN MATCHED THEN 
    UPDATE SET ct_current.Description = '0%'
WHEN NOT MATCHED THEN
    INSERT (Description, ShareAmount)
    VALUES (ct_value.Description, ct_value.ShareAmount);
GO

Error:

Msg 156, Level 15, State 1, Line 1 Incorrect syntax near the keyword 'into'. Msg 102, Level 15, State 1, Line 2 Incorrect syntax near 'ct_value'.

Was it helpful?

Solution 2

I realized that I had the SQL Server 2008 R2 client, but the server is SQL Server 2005.

OTHER TIPS

Try

MERGE MyTable AS ct_current
USING (SELECT '0%' as Description, '0' as ShareAmount) ct_value
  ON ct_current.ShareAmount = ct_value.ShareAmount
WHEN MATCHED THEN 
  UPDATE SET ct_current.Description = '0%'
WHEN NOT MATCHED THEN
  INSERT (Description, ShareAmount)
  VALUES (ct_value.Description, ct_value.ShareAmount);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top