1:
select * from ss1.data1.dbo.test1('P011011085') 应该可以
2:
select * from openquery(ss1,'select * from data1.dbo.test1(''P011011085'')')

解决方案 »

  1.   

    declare @a varchar(10)
    set @a = 'P011011085'
    1:
    select * from ss1.data1.dbo.test1(@a) 应该可以
    2:
    select * from openquery(ss1,'select * from data1.dbo.test1(' + @a + ')')
      

  2.   

    select * from ss1.data1.dbo.test1(@a)  不可以select * from openquery(ss1,'select * from data1.dbo.test1(''P011011085'')')  可以select * from openquery(ss1,'select * from data1.dbo.test1(' + @a + ')')  不行参数改为变量后,执行时出现如下错误:Server: Msg 170, Level 15, State 1, Line 3
    Line 3: Incorrect syntax near '+'.烦请指教.
      

  3.   

    这样可以的:declare @a varchar(10),@sql varchar(200)
    set @a = '00000011'
    set @sql='select * from openquery(hr,''select * from hr.dbo.EmpList('''''+@a+''''')'')'
    print @sql
    exec(@sql)
      

  4.   

    Variables cannot be passed into the OPENQUERY function, so the SQL statement needs to be constructed as a string and then passed into the stored procedure sp_executesql as the SQL statement parameter. This is not the most convenient method, but can work efficiently. Calling remote stored procedures is another possibility and often a better solution.