hawand5
asked on
SQLServer and if/case in where clause
Have a stored proc for displaying customer info which appears as:
create proc custinfo @nonzero smallint as
select * from customer
where...
The parm @nonzero (1 or 0) limits the display of customer's balances. If
@nonzero = 1 then only customers with balances <> 0 display. Otherwise
all customers display.
My issue is how best to express the where clause to accomodate @nonzero.
Currently I have: ((@nonzero = 1 and balance <> 0) or (@nonzero = 0)). Surely there's a
better solution.
create proc custinfo @nonzero smallint as
select * from customer
where...
The parm @nonzero (1 or 0) limits the display of customer's balances. If
@nonzero = 1 then only customers with balances <> 0 display. Otherwise
all customers display.
My issue is how best to express the where clause to accomodate @nonzero.
Currently I have: ((@nonzero = 1 and balance <> 0) or (@nonzero = 0)). Surely there's a
better solution.
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.