Chasen Bettinger Chasen Bettinger - 6 months ago 16
SQL Question

Confusing Syntax Error (FROM statement)

I am trying to update table 1's date column to a date in the future, otherwise known as decommissioned. I am getting a syntax error under the FROM statement. There is no other information that I am given other than


INCORRECT SYNTAX NEAR 'FROM'.


Any help?

UPDATE [database1].[dbo].[table1]
SET [database1].[dbo].[table1].[datecolumn1] = '9999-12-31 00:00:00.000'
WHERE [database1].[dbo].[table1].[END_DATE] > GETDATE()
FROM [database1].[dbo].[table1]
INNER JOIN [database2].[dbo].[table2] ON [database1].[dbo].[table1].[namecolumn1] = [database2].[dbo].[table2].[namecolumn2]
GO

Answer

Your WHERE clause should be after FROM :

UPDATE [database1].[dbo].[table1]
SET [database1].[dbo].[table1].[datecolumn1] = '9999-12-31 00:00:00.000'
FROM [database1].[dbo].[table1] 
INNER JOIN [database2].[dbo].[table2] ON [database1].[dbo].[table1].[namecolumn1]=[database2].[dbo].[table2].[namecolumn2]
WHERE [database1].[dbo].[table1].[END_DATE] > GETDATE() 
GO