I have this query in my sql
if (select count(*) from sys.columns where object_id = (select object_id from sys.tables where name = 'CLIENT_STATUS')) = 4 insert into CLIENT_STATUS select 'NA', 'Inactive', 0, 0 --old version else insert into CLIENT_STATUS select 'NA', 'Inactive', 0, 0, 1 --new version
The result of select count(*) from sys.columns where object_id = (select object_id from sys.tables where name = 'CLIENT_STATUS') is 4, but it always seems like it is executing the 5th variant of the else version of the query.
What am I doing wrong with the if statement?
UPDATE:
It seems like both recordings are done, because if I do
if (select count(*) from sys.columns where object_id = (select object_id from sys.tables where name = 'CLIENT_STATUS')) = 5 insert into CLIENT_STATUS select 'NA', 'Inactive', 0, 0, 1 --new version else insert into CLIENT_STATUS select 'NA', 'Inactive', 0, 0 --old version
I get the same error, but now she says what the first statement does.
UPDATE2: Mikael Eriksson had the correct answer, I changed my code to this to fix it.
if ((select count(*) from sys.columns where object_id = (select object_id from sys.tables where name = 'CLIENT_STATUS')) = 5) execute ('insert into CLIENT_STATUS select ''NA'', ''Inactive'', 0, 0, 1') --new version else execute ('insert into CLIENT_STATUS select ''NA'', ''Inactive'', 0, 0') --old version