SQl if statement in where clause

  • How do I make this a sql statement?

    ----------------------------------------------------------------------------------------------

    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

  • have a look at the case statement and use it in your select query. It will have a performance hit. Have you als othought of creting a lookup table and joining to it to translate values?

  • No I haven't and I don't know how

  • Here you go:

    A solution

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I'm working off of the test server

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply