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

简单查询做成存储过程?
简单查询做成存储过程?
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=''张山'''