如果@ param1<> 0离开(value1,4)= @ param1,否则不在where条件下执行此部分 [英] Where if @param1 <>0 left(value1, 4)=@param1 otherwise don't execute this part in the where condition

查看:55
本文介绍了如果@ param1<> 0离开(value1,4)= @ param1,否则不在where条件下执行此部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果@ param1<> 0离开(value1,4)= @ param1 

否则不要不要在where条件下执行此部分

如何编写查询?



Soumya



我尝试过:



其中LEFT(ISNULL(value1,0000), 4)= 

CASE
WHEN @ param1<> 0那么过去(@ param1 AS NVARCHAR(12))
END





但如果<$ p,这将不会执行$ p> @param1

= 0

解决方案

  WHERE ((@ PARAM1<> 0  AND   left (value1, 4 )= @ param1) OR  @ PARAM1 =  0 


尝试以下 -

  WHERE  @ param1  ==  0  OR  LEFT (ISNULL(value1, 0000 ), 4 )= @ param1)





逻辑或在这里诀窍。当@ param1的值为0时,它不会执行第二部分。



希望,它有帮助:)

如果有问题请告诉我这没有帮助。


Hi,

where if @param1 <>0   left(value1,4)=@param1

otherwise don't execute this part in the where condition
How to write the query?

Soumya

What I have tried:

where LEFT(ISNULL(value1, 0000), 4) =

CASE
WHEN @param1 <> 0 THEN CAST(@param1 AS NVARCHAR(12))
END	



But this won't execute if

@param1

=0

解决方案

WHERE ((@PARAM1<>0 AND left(value1,4)=@param1) OR @PARAM1= 0)


Try following-

WHERE (@param1 == 0) OR (LEFT(ISNULL(value1, 0000), 4) =@param1)



Logical OR does the trick here. When value of @param1 is 0 it will not execute the second part.

Hope, it helps :)
Please let me know if this doesn't help.


这篇关于如果@ param1&lt;&gt; 0离开(value1,4)= @ param1,否则不在where条件下执行此部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆