I have problem with conditional SQL script in SQL Server 2008.
When I run each command as separate everything is OK and I successfully update my DB
But when I split everything into one command I get errors:
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ';'.Msg 207, Level 16, State 1, Line 1
Invalid column name 'sAdvertTypeCode'.Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'end'.
So I tried without semicolon ';'
And error was:
Msg 102, Level 15, State 1, Line 3
Incorrect syntax near ')'.Msg 207, Level 16, State 1, Line 1
Invalid column name 'sAdvertTypeCode'.Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'end'.
My script :
IF COL_LENGTH('TechnicalDialogue', 'sAdvertTypeCode') IS NULL
begin
ALTER TABLE TechnicalDialogue ADD sAdvertTypeCode varchar(40) ;
go
UPDATE TechnicalDialogue SET sAdvertTypeCode = 'advert.type.broadcast' ;
go
Select * FROM TechnicalDialogue;
end
I don't have a lot experience with SQL Server so I'm a little bit confused.