SQL存储过程,条件作为参数传入时,执行无反应! 何解??

一个SQL存储过程,有2参数 @condition 和 @conditionValue。 在当 @condition =''时;执行 select * from tb ;
否则 select * from tb where @condition lick '%'+@_conditionValue+'%'

为什么只有当 @condition=''时候能够查询出记录, 不为''时候 就查不出记录了??
上面的 lick 是like 打这里打错了

select * from tb where @condition like '%'+@_conditionValue+'%'

测试 @condition 也能传入进去 但是就是@_conditionValue 只要一有值 他就无数据了

第1个回答  2012-10-19
是不是因为本来就没有数据,你直接用sql语句查询确认下结果然后再检查你的过程追问

有的

第2个回答  2012-10-19
因为,你后面的语句有错误啊,lick?Maybe "like" is the correct.追问

like ……是对的 我这里打错了

追答

那,还是不出结果吗?

追问

不是来 很奇怪……

第3个回答  2012-10-19
declare @SqlString varchar(max)
Set @SqlString = 'select * from tb '
IF@condition <>''
Set @SqlString = @SqlString + 'WHERE ' + @condition + 'LIKE N''' + @_conditionValue +'%'''

Exec @SqlString本回答被网友采纳