存储过程输入where参数问题?

CREATE PROCEDURE sp_test
@a varchar(100)='title',
@b varchar(100)='titles',
@c varchar(100)='BU%',
AS
exec('select title_id,' + @a +' from ' + @b + ' where title_id = ' + @b )
GO
SQL出错提示:
'BU%' 附近有语法错误。
---------------------------------------------------------------

CREATE PROCEDURE sp_test
@a varchar(100)='title',
@b varchar(100)='titles',
@c varchar(100)='BU%',
AS
exec('select title_id,' + @a +' from ' + @b + ' where title_id like @c ')
GO

---------------------------------------------------------------

你把'BU%' 後面的","去掉
---------------------------------------------------------------

去掉就好了
---------------------------------------------------------------

对楼上的仁兄说的对,我没有注意到。不过你的exec('select title_id,' + @a +' from ' + @b + ' where title_id = ' + @b )还是换成我的吧。

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus