SQLTeam.com | Weblogs | Forums

Is there a better way to do this where clause?

SELECT DISTINCT
r.id, r.IdNum, r.datelastaltered,f.NAME
FROM
tbltrkrecord r
LEFT JOIN
tbltrkfuncsubarea f
ON r.funcsubareaid = f.id
WHERE
r.recordtypeid = 13
AND
(
( f.NAME IN
(
'Settlement',
'Overseas Allowances',
'LQA Reconciliation',
'Travel Order'
)
AND Dateadd(month, -73, Getdate()) >= r.datelastaltered )
OR
(
( f.NAME NOT IN
(
'Settlement',
'Overseas Allowances',
'LQA Reconciliation',
'Travel Order'
)
AND Dateadd(month, -37, Getdate()) >= r.datelastaltered )
)
)

--There is an alternate way. I don't know that it's any better:

WHERE
r.recordtypeid = 13 AND
(Dateadd(month, case when 
f.NAME IN
(
'Settlement',
'Overseas Allowances',
'LQA Reconciliation',
'Travel Order'
)
then -73 else -37 end, Getdate()) >= r.datelastaltered )