CREATE PROCEDURE [dbo].[SelWhereInfo]
@table varchar(10),
@strwhere varchar(50) AS
if(@strwhere<>'')
begin
exec('select * from '+@table+'  where name like  %' + @strwhere + '%' )
end
else
begin
exec('select * from  '+@table)
endGO
大家帮忙看看当传入参数执行模糊查询的时候,总说@strwhere 附近有错误exec('select * from '+@table+'  where name like  %' + @strwhere + '%' )
这句话应该怎样写?

解决方案 »

  1.   

    exec('select * from '+@table+'  where name like  '%' + @strwhere + '%' ') 
      

  2.   

    exec('select * from '''+@table+'''  where name like  ''%' + @strwhere + '''%') 
      

  3.   

    exec('select * from '+@table+'  where name like  '%'+ @strwhere + '%'' ) 
      

  4.   

    exec('select * from '+@table+'  where name like  '%'''+ @strwhere +'''%'' ) 
      

  5.   

    晕了
    exec('select * from '+@table+'  where name like  ''%'+ @strwhere +'%''' )