SQL- Ensuring query does not include results where a certain column in null?
Below is the query I am using in order to check how many rows in my table have a date older than 01/01/2015 (TIMESTAMP).
How can I alter this query to ensure that it does not include any results where the DATE_INSERTED column is null?
Also, if this is not the most efficient way to check for this condition, I would appreciate alternatives.
SELECT COUNT(*) FROM TABLE_NAME WHERE DATE_INSERTED NOT BETWEEN '01-JAN-2015 00.00.00.00' AND '18-JAN-2016 00.00.00.00';
You want to use a is not null Here's your query updated:
SELECT COUNT(*) FROM TABLE_NAME WHERE DATE_INSERTED NOT BETWEEN '01-JAN-2015 00.00.00.00' AND '18-JAN-2016 00.00.00.00' AND DATE_INSERTED is not null;
New line spacing is optional. Although it may look misleading by having: between param1 and param2 and column is not null... the first where condition you set (between) only takes two parameters, so the next AND is treated as default. Whereas the first is the separation between the first and second BETWEEN params.