I need to do one INSERT or another depending if a column exist because of different versions of the same table.
I did the approach at this thread but SQL Server's pre check or 'sort of compilation' detects an error that would not fail during execution time.
Here's some code
IF COL_LENGTH('TableA', 'Column2') IS NOT NULL
BEGIN
INSERT INTO [dbo].[TableA]([Column1], [Column2], [Column3], [Column4])
SELECT value1, value2, value3, value4
END ELSE
BEGIN
INSERT INTO [dbo].[TableA]([Column1], [Column3], [Column4])
SELECT value1, value3, value4
END
Any workaround?