Link to home
Start Free TrialLog in
Avatar of jfreeman2010
jfreeman2010Flag for United States of America

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,
ASKER CERTIFIED SOLUTION
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jfreeman2010

ASKER

yes, both are works.  BIG THANKS!!

Can you please tell me why or how @ordernumber = 0 OR ordernumber = @ordernumber this will work?

thanks,

and(@ordernumber = 0 OR ordernumber = @ordernumber )

if @ordernumber is 0 the the condition always evaluates to true hence you get all the data
THANKS!!!
THANKS!!