Link to home
Start Free TrialLog in
Avatar of bibi92
bibi92Flag for France

asked on

Error on sql statement

Hello,

When I try :

declare @sql2 varchar(max)
set @sql2 = 'IF exists (select *  from  ['+@SrvAbonne + '].['+ @DbCible + '].dbo.sysobjects where name = ''MSreplication_subscriptions'')
BEGIN
delete from ['+@SrvAbonne + '].['+ @Dbcible + '].dbo.MSreplication_subscriptions
where [publication] like ''' + @publication + ''' end'
execute (@sql2)
print(@sql2)

I have this error:
The OLE DB provider "SQLNCLI" for linked server "SRVTEST" does not contain the table ""TEST"."dbo"."MSreplication_subscriptions"". The table either does not exist or the current user does not have permissions on that table. #7314

I don't understand why because I check 'IF exists (select *  from  ['+@SrvAbonne + '].['+ @DbCible + '].dbo.sysobjects where name = ''MSreplication_subscriptions'')

Thanks

Regards

bibi
ASKER CERTIFIED SOLUTION
Avatar of Nico Bontenbal
Nico Bontenbal
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bibi92

ASKER

I want to execute but I have another error :
'IF (select *  from  ['+@SrvAbonne + '].['+ @DbCible + '].dbo.sysobjects where name = ''MSsubscription_agents'')
then
delete from ['+@SrvAbonne + '].['+ @Dbcible + '].dbo.MSreplication_subscriptions
where [publication] like ''' + @publication + ''' end if' :

An expression of non-boolean type specified in a context where a condition is expected, near 'then'. #4145

Thanks
Regards
bibi
Avatar of bibi92

ASKER

Thanks bibi