首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

简单查询做成存储过程?该如何解决

2012-05-10 
简单查询做成存储过程?简单查询做成存储过程?create proc testtype@queryvarchar(8000)ASexec(select*fro

简单查询做成存储过程?
简单查询做成存储过程?
create proc testtype
@query varchar(8000)
AS
exec('select*from t_cyryglb '+ @query)
go 

exec testtype 'where xm='张山''

难道不能整个条件'where xm='张山''传送参数吗?只能传送‘张山’这个参数吗?因为软件中有万能组合查询,难道这样不能做成存储过程?

create proc testtype
@query varchar(8000)
AS
select*from t_cyryglb where xm=@query
go 

exec testtype '张山'
像上面这样能通过,但这样只能传送固定的条件,能否传送任意组合的条件?


[解决办法]
可以穿整个条件的,但是你的格式写错了,字符串里面的一个'是要变成两个''的
你的where条件变成

SQL code
exec testtype 'where xm=''张山''' 

热点排行