我写了个存储过程:
create procedure Pr_GetSearchPreBooks
(@BClassName varchar(50),
@sSearchKey varchar(50),
@sSearchValue varchar(50)
)
as begin
exec
('
select * from PreBorBook where BClassName='+@BClassName+'
and '+@sSearchKey+' like ''%'+@sSearchValue+'%''
')
end
为什么运行时出错说我表中对应的BClassName列名无效

解决方案 »

  1.   

    exec
    ('
    select * from PreBorBook where BClassName='''+@BClassName+'''
     and '+@sSearchKey+' like ''%'+@sSearchValue+'%''
    ')
    end
      

  2.   

    exec
    ('
    select * from PreBorBook where BClassName='''+@BClassName+'''
    and '+@sSearchKey+' like ''%'+@sSearchValue+'%''
    ')
      

  3.   

    select * from PreBorBook where BClassName
    --------------------
    PreBorBook里面有这个栏位BClassName么?
      

  4.   

    估计是没有,但不加',有bcassname也得报错
      

  5.   

    create procedure Pr_GetSearchPreBooks 
    (@BClassName varchar(50), 
    @sSearchKey varchar(50), 
    @sSearchValue varchar(50) 

    as begin 
    exec 
    (' 
    select * from PreBorBook where BClassName='''+@BClassName+''' 
    and '+@sSearchKey+' like ''%'+@sSearchValue+'%'' 
    ') 
    end