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

简单查询问题
CREATE       procedure   search_info
@tab   varchar(50),                                           --需查询的表格
@typ   varchar(50),                                           --查询的类型
@inf   varchar(50),                                           --根据查询内容范围(title,content,title&content)
@content   varchar(1000)                                 --查询的内容
as
                declare   @sql   varchar(300)
                set   nocount   on
set   @sql= "select   title,uptime,content   from   "+@tab+ "   where   type= "+@typ+ "   and   "+@inf+ "   like   '% "+@content+ "% '   order   by   id   desc "
exec(@sql)
--------------------------
为什么会创建不成功,如何规范传入参数的调用,我在这里先谢谢各位了.

------解决方案--------------------
这样写:
CREATE procedure search_info
@tab varchar(50), --需查询的表格
@typ varchar(50), --查询的类型
@inf varchar(50), --根据查询内容范围(title,content,title&content)
@content varchar(1000) --查询的内容
as
declare @sql varchar(300)
set nocount on
set @sql= 'select title,uptime,content from '+@tab+ ' where type= '+@typ+ ' and '+@inf+ ' like ' '% '+@content+ '% ' ' order by id desc '
exec(@sql)
------解决方案--------------------
CREATE procedure search_info
(
@tab varchar(50), --需查询的表格
@typ varchar(50), --查询的类型
@inf varchar(50), --根据查询内容范围(title,content,title&content)
@content varchar(1000) --查询的内容
)
as
set nocount on
declare @sql varchar(300)

set @sql= "select title,uptime,content from "+@tab+ " where type= "+@typ+ " and "+@inf+ " like '% "+@content+ "% ' order by id desc "
exec(@sql)