Board index » delphi » MS SQL Server - Columns Exists problem. Condition not met but SQL statment still fails
DC
Delphi Developer |
MS SQL Server - Columns Exists problem. Condition not met but SQL statment still fails2007-09-05 03:40:41 PM delphi206 Hi all, we have a "DO NO HARM" script that gets run our DB whenever an update to our software is applied. The part shown below is fine when the condition is met and it dies the updates and drops the column. If it is ran again, the conditions are NOT met so none of the updates should occur - Hence "DO NO HARM" Howeever, it seems that something behind the scenes checks the statments anyway. For instance, if I run the script below a second time, i get the error "Msg 207, Level 16, State 1, Line 17 Invalid column name 'bGA'." How can I get round this? and execute the statement without error. if EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'SupplierFacilityConfiguration' AND COLUMN_NAME = 'bGA' ) BEGIN if EXISTS( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'SupplierFacilitySection' AND COLUMN_NAME = 'GA' ) BEGIN Blah Blah.......... UPDATE SupplierFacilitySection SET GA = 1, ScreenX = 100, ScreenY = 100, ScreenWidth = 100, ScreenHeight = 100 WHERE SupplierFacilitySection.ConfigurationId in ( Select ConfigurationId from SupplierFacilityConfiguration WHERE bGA = 1 ) ALTER TABLE SupplierFacilityConfiguration DROP COLUMN bGA END END |