Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Case in Where Statement

Author  Topic 

baze7
Yak Posting Veteran

58 Posts

Posted - 2010-03-04 : 17:13:10
What is the correct way to do this?
ALTER procedure Rpt_BookingsDetalBySlsSPLC(
@BegOrderDate Datetime = null,
@EndOrderDate Datetime = null,
@SlsPerson nvarchar (8) = null
)
as
select * from BookingsDetailBySls

where activity_date between isnull(@BegOrderDate,dbo.lowdate()) and isnull(@EndOrderDate,dbo.HighDate())
and TotalOrders <> '0'
and
case when @SlsPerson = 'lc' then slsman like 'la%' or slsman = 'fd'
else
slsman = @SlsPerson

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2010-03-05 : 02:16:46
try like this

select * from BookingsDetailBySls
where activity_date between isnull(@BegOrderDate,dbo.lowdate()) and isnull(@EndOrderDate,dbo.HighDate())
and TotalOrders <> '0'
and
( (
@SlsPerson = 'lc' AND ( slsman like 'la%' or slsman = 'fd' )
)
OR slsman = @SlsPerson
)

Go to Top of Page
   

- Advertisement -