新手问题!!!
存储过程:
CREATE PROCEDURE proc_BookSearch
@sBClassID varchar(2),@sSearchValue varchar(100),@sSearchKey varchar(10)
AS
declare @sql varchar(200)
set @sql = 'select a.*,b.Pub_Name from T_Books a,T_Publishers b
where a.Pub_ID=b.Pub_ID and a.BClass_ID= '+ @sBClassID+ ' and '+ @sSearchKey + ' like ' ' '+ @sSearchValue +
' ' ' order by a.Book_AddDate desc '
exec (@sql)
GO
调用:
exec proc_BookSearch '01 ', 'Book_Name ', '%c% '
错误:
服务器: 消息 170,级别 15,状态 1,行 2
第 2 行: 'c ' 附近有语法错误。
------解决方案--------------------try
alter PROCEDURE proc_BookSearch
@sBClassID varchar(2),@sSearchValue varchar(100),@sSearchKey varchar(10)
AS
declare @sql varchar(200)
set @sql = 'select a.*,b.Pub_Name from T_Books a,T_Publishers b
where a.Pub_ID=b.Pub_ID and a.BClass_ID= '+ @sBClassID+ ' and '+ @sSearchKey + ' like ' '% '+ @sSearchValue +
'% ' ' order by a.Book_AddDate desc '
exec (@sql)
GO
--调用:
exec proc_BookSearch '01 ', 'Book_Name ', 'c '
------解决方案--------------------exec proc_BookSearch '01 ', 'Book_Name ', '%c% '
改成:
exec proc_BookSearch '01 ', '%c% ', 'Book_Name '