Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
Posted
Updated 12-Nov-17 23:44pm
v4

Try following-
SQL
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.
 
Share this answer
 
v2
Comments
soumyaraj 13-Nov-17 7:03am    
Yes it works!
Thank you for your help
Suvendu Shekhar Giri 13-Nov-17 7:40am    
Glad that it helped! :)
SQL
WHERE ((@PARAM1<>0 AND left(value1,4)=@param1) OR @PARAM1= 0)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900