I wrote a (apparently) straightforward SQL fragment that deletes a column after it ensures that the column exists.
Problem: if the column does NOT exist, the code inside the IF clause complains that it cannot find the column! Well, yes, why is it inside an IF clause!
So my question is: why does the part of the code that should not be executed give errors?
Here's a snippet:
IF exists (select * from syscolumns
WHERE id=object_id('Table_MD') and name='timeout')
BEGIN
ALTER TABLE [dbo].[Table_MD]
DROP COLUMN timeout
END
GO
... and here's the error:
Error executing SQL script [...]. Invalid column name 'timeout'
I am using Microsoft SQL Server 2005 Express Edition.
source
share