I have a problem with a stock procedure precisely in @sqlstmt that return the following error :
Msg 105, Level 15, State 1, Line 2Unclosed quotation mark after the character string ')'.
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near ')'.
alter PROCEDURE Eqp_compare( @serverDistant varchar(max)='server\instance' ) AS BEGIN SET NOCOUNT ON; declare @listetable as varchar(max) declare @eqp as varchar(max) declare @cou_eqp as int declare @sqlstmt as varchar(max) create table #t_eqp(Equipement varchar(max)) create table #t_listeqp(Equipement varchar(max), listable varchar(max) ) set @serverDistant=ltrim(rtrim(@serverDistant)) declare @serverDistantS sysname set @serverDistantS=cast(@serverDistant as sysname) declare @rc int set @rc=1 declare @TABLEstore varchar(255) begin try exec @rc =sp_testlinkedserver @serverDistantS end try begin catch end catch if @rc<>0 begin select 'Le serveur distant ' +isnull(@serverDistant,'?') +' n''est pas configuré' Erreur return end set @serverDistant=replace(replace('['+ @serverDistant+']',']]',']'),'[[','[') --print @serverDistant set @sqlstmt ='select Eqp_nom from master..eqp_traite where flag_compare = 1 intersect select Eqp_nom from '+@serverDistant+'.master.[dbo].eqp_traite where flag_compare = 1' print @sqlstmt Insert into #t_eqp exec(@sqlstmt)