jfreeman2010
asked on
t-sql store procedure - condition in where
I have a store procedure with 1 parameter name ordernumber, when ordernumber = 0, I need to select all the order, or when ordernumber > 0 will select that order.
ex:
select *
from order
where order_status = 'active'
and ordernumber = @ordernumber
what can I do in the where to select all order?
thanks,
ex:
select *
from order
where order_status = 'active'
and ordernumber = @ordernumber
what can I do in the where to select all order?
thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and(@ordernumber = 0 OR ordernumber = @ordernumber )
if @ordernumber is 0 the the condition always evaluates to true hence you get all the data
ASKER
THANKS!!!
ASKER
THANKS!!
ASKER
Can you please tell me why or how @ordernumber = 0 OR ordernumber = @ordernumber this will work?
thanks,