I've got the following query:
IF EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'NotificationTableLogRows' AND COLUMN_NAME = 'DestinationAddress') BEGIN
UPDATE NotificationTableLogRows
SET [HandlerID] = m.ID
FROM [Unicare].dbo.MobileDevices m
WHERE HandlerID is null
AND m.CallNumber = NotificationTableLogRows.DestinationAddress AND NotificationTableLogRows.HandlerTypeID = 2
END
print 'end'
But after running this, I still got the error:
Msg 207, Level 16, State 1, Line 6
Invalid column name 'DestinationAddress'.
It should however just print end
What am I doing wrong?
Edit:
Even with:
IF 1 = 0 BEGIN
UPDATE NotificationTableLogRows
SET [HandlerID] = m.ID
FROM [Unicare].dbo.MobileDevices m
WHERE HandlerID is null
AND m.CallNumber = NotificationTableLogRows.DestinationAddress AND NotificationTableLogRows.HandlerTypeID = 2
END
It produces the same error, the problem seems to be in the way sql checks the query pre executing..
NotificationTableLogRows
table, perhaps under a different schema?