日期:2014-05-18  浏览次数:20372 次

sql存储过程为什么报错说没声明变量,已经声明了的
create   procedure   Search
@thedatabase   varchar(50),
@thekeys   varchar(100)
as
select   *   from   @thedatabase   where   protitle   like   '% '   +@thekeys+   '% '   order   by   addtime   desc
go

这是我做查询搜索用的,从页面上传递两个参数进来。
一个表名,一个 关键字。。。。
 但是建立存储过程中报错。说 我 的 select语句里的@thedatabase
没声明变量。 明明声明了啊 !

------解决方案--------------------
表名不能使用变量代替吧!
------解决方案--------------------
create procedure Search
@thedatabase varchar(50),
@thekeys varchar(100)
as
select * from @thedatabase where protitle like '% ' +@thekeys+ '% ' order by addtime desc
go

这是我做查询搜索用的,从页面上传递两个参数进来。
一个表名,一个 关键字。。。。
 但是建立存储过程中报错。说 我 的 select语句里的@thedatabase
没声明变量。 明明声明了啊 !

这个错误我以前也遇到过,它的意思好像是addtime没有申明,还有就是你的表都不确定,那么字段addtime从何而来了