set @SQL='set @Other='''' select @Other = @Other + name + ''<br>''  
         from others where otherId in @OtherId'改成如下:
set @SQL='set @Other='''' select @Other = @Other + name + ''<br>''  
         from others where otherId in ('+@OtherId+')'

解决方案 »

  1.   

    谢谢!!! 这个方法我也知道。我的意思是在sql语句中的变化参数,全部通过后面指定,怎么做呢?
      

  2.   

    declare @Other varchar(250)
    declare @SQL nvarchar(500)
    declare @OtherId varchar(100)
    set @OtherId='1,2'set @SQL='set @Other='''' select @Other = @Other + name + ''<br>''  
             from others where otherId in (' + @OtherId +')'
    exec sp_executesql @SQL,
                       N' @Other varchar(250) output, @OtherId varchar(100)',
                       @Other  output, @OtherIdselect @Other