Reputation: 39
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 200? 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
Upvotes: 0
Views: 234
Reputation: 201437
If I understand your question, then you're looking for something like
String sql = "SELECT SUM(cost) FROM product WHERE "
+ "use_by_date is NULL OR use_by_date < best_before_date";
Upvotes: 1