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
 General SQL Server Forums
 New to SQL Server Programming
 sql if statement in where clause

Author  Topic 

TCB
Starting Member

1 Post

Posted - 2014-11-20 : 13:52:57

How do I add the bottom line to my statement?

SELECT
AgentID,
PaymentAmount

FROM Table A

WHERE
DATEOFPAYMENT

GROUP BY
CollectorNumber

ORDER BY
CollectorNumber,
LastName,
DateofPayment,
PaymentAmount
----------------------------------------------------------------------------------------------
if DATEOFPAYMENT = yesterday then PaymentAmount else 0 as 'previous day'
or
if DATEOFPAYMENT = current_Month then PaymentAmount else 0 as 'MTD'
or
if DATEOFPAYMENT = current_Year then PaymentAmount else 0 as 'YTD

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-20 : 14:01:03
CASE, not IF


SELECT
AgentID,
PaymentAmount,
CASE WHEN DATEOFPAYMENT = yesterday then PaymentAmount else 0 as 'previous day' END
...
Go to Top of Page
   

- Advertisement -