I'm trying the following code to update a column. My need is that it will not error, so I can run 200 of these at one time.
IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'SOMETABLE' AND COLUMN_NAME = 'SOMECOLUMN') BEGIN UPDATE A SET A.SOMECOLUMN = NULL FROM stg_CPIData_Mart_Load as A WHERE A.SOMECOLUMN = 'NULL' or A.SOMECOLUMN = '' END;
Although it's not working. If the column is not found I get an error:
Msg 207, Level 16, State 1, Line 1 Invalid column name 'SOMECOLUMN'. Msg 207, Level 16, State 1, Line 1 Invalid column name 'SOMECOLUMN'.
-Al H