jeudi 26 mars 2015

SQL statement check IS NOT NULL before comparing two dates

Using SQLite and JDBC in java netbeans, executing through prepared statements,



String sql = "SELECT SUM(cost) FROM product WHERE use_by_date < best_before_date";


I want to check that use_by_date in my table is null before executing this query is it possible? I need it to be null sometimes


EDIT: I have also tried



String sql = "SELECT SUM(cost) FROM product WHERE use_by_date IS NULL OR use_by_date < before_date ;


When i try this it returns cost as 400 but the actual cost is 400? i can't understand why it does this.


Without use_by_date < before_date it returns 200 as total cost. Also its not because there is more products being selected, I only have two products in there currently at 100 cost each


Aucun commentaire:

Enregistrer un commentaire