I have a SSIS which in order to work has to have some specific tables. Therefore I have made an "Execute Sql Task" package which first verifies if table exists and has the specific number of columns, if not then the existing table is being dropped and then re-created with needed columns. Bottom line is that my sql script looks like this (in the same "execute sql task" package):
declare @nr integer;
set @nr=(select COUNT (*)
from dbo.syscolumns
where id= (select id
from dbo.sysobjects
where id = object_id(N'[bogdan].[dbo].[my_table]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1));
if (@nr<>10 and @nr<>0) /*to verify if my_table exists and has the required number of colums - 10 */
drop table [bogdan].[dbo].[my_table]
go
declare @nr1 integer;
set @nr1=(select count(*)
from dbo.sysobjects
where id = object_id(N'[bogdan].[dbo].[My_table]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1);
if @nr1=0
create table bogdan.dbo.my_table (....) on [PRIMARY]
go
/*end of script*/
The problem is that even when I have dropped the table (my_table from the example above), there is still an object named "my_table" in sysobjects. The @nr1 variable has 1 as its value, instead of 0 therefore the table with needed structure is not created, as if clause does not get executed.
Any hints?
Thanks,