---B.创建链接服务器
---用SQL命令建立与本Server的Linked Server.
Exec sp_addlinkedserver '172.26.40.8','','SQLOLEDB','172.26.40.8'
Exec sp_addlinkedsrvlogin '172.26.40.8','false',null,'sa','123'
exec sp_serveroption '172.26.40.8','rpc','true'
exec sp_serveroption '172.26.40.8','rpc out','true' --这个允许调用链接服务器上的存储过程
调用示例如下,
Create Table #TempCheckResult(iResult varchar(12),iMessage nvarchar(200))
Declare @iSQL nvarchar(200)
Set @iSQL= 'Exec usp_PAL_CheckCompUsability '+'''SW89080571GN'''+',''W8905001U632A'''+',''Repair'''
Insert Into #TempCheckResult EXEC(@iSQL) ---此句会报错:An INSERT EXEC statement cannot be nested.
Insert Into #TempCheckResult EXEC [172.26.40.6].PAL_COMPSN_P80.dbo.sp_executesql @iSQL ---@iSQL --须为nvarchar,varchar会报错