Purple Owl
Purple Owl

Reputation: 137

WHERE AND SQL statement

I am trying to have 2 where clause. The SQL statement works before I put

AND fborders.date="+todayDate);

So is there a error at my sql statement because it does not work?

DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = new Date();
String todayDate = dateFormat.format(date);


("
SELECT Id,Name,quantity,date,time,
FROM orders
WHERE status='pending'
  AND date="+todayDate
);

Upvotes: 0

Views: 126

Answers (3)

beny23
beny23

Reputation: 35018

Strictly speaking you don't have to pass todays date as a parameter at all.

Assuming that your DATE column is a DATE type, you could just use:

SELECT Id,Name,quantity,date,time
  FROM orders
 WHERE status='pending'
   AND date=current_date()

or is DATE is a VARCHAR column:

SELECT Id,Name,quantity,date,time
  FROM orders
 WHERE status='pending'
   AND date=date_format(current_date(), '%d/%m/%Y')

Upvotes: 1

Alexander
Alexander

Reputation: 2318

The date needs to be in quotes too. Change it to this:

AND date='" + todayDate + "'"

Upvotes: 3

Vishal Suthar
Vishal Suthar

Reputation: 17194

You missed single quote sign. Date needs quotes around that.

Here you go:

AND fborders.date='" + todayDate + "'"

Upvotes: 4

Related Questions