Lewis Smith
Lewis Smith

Reputation: 1345

SQL only check column if its not null

Really hard to explain but here goes

I have a query that checks a number of fields, but on one of them makeCall I need to display it if its null, but if its not null then I need to check that the date is = to today, if it is display, if its not don't.

Here is what I have so far:

    SELECT
        renewaldate,
        DATEDIFF(renewaldate, CURDATE()) AS DaysUntilRenewalDate,
        orders.*, customers.*
    FROM
        orders
    JOIN customers ON orders.CustomerNumber = customers.CustomerNumber
    WHERE 
    RenewalDate < DATE_ADD(CURDATE(), INTERVAL 23 DAY)
    AND RenewalDate > DATE_SUB(CURDATE(), INTERVAL 4 DAY)
    AND IF MakeCall IS NOT NULL THEN WHERE ITS = TO TODAY?
    ORDER BY
        RenewalDate

The "AND IF MakeCall IS NOT NULL THEN WHERE ITS = TO TODAY?" is where it would go

Upvotes: 0

Views: 63

Answers (1)

Lewis Smith
Lewis Smith

Reputation: 1345

AND (MakeCall IS NULL OR MakeCall = today)

As suggested by jarlh

Upvotes: 2

Related Questions