tags:

views:

55

answers:

4

Hi,

Not able to execute a query ,i need to check if end date is greater than today in the following query

Getting an error invalid query

select * from table1 where user in  ('a') and END_DATE >'2010-05-22'

getting an error liter string does not match

+1  A: 

Multiple conditions are joined by AND or OR, not multiple WHERE's

select * 
  from table1 
 where user in ('a') 
   AND END_DATE >'2010-05-22'
Mark Baker
+3  A: 

You cannot use WHERE two times. It should be

SELECT * FROM table1 WHERE user in ('a') AND END_DATE >'2010-05-22'

Also, if you want to check whether END_DATE is greater than today just use

SELECT * FROM table1 WHERE user in ('a') AND END_DATE > CURDATE()
nico
curdate() is only applicable to sql server. current_date is perhaps more portable.
araqnid
Araqnid is right: CURDATE is not a generic function.
APC
@araqnid: true, anyway it works also in MySQL
nico
+2  A: 

Your query contains two WHERE clauses, if you need to combine two or more predicates you must use the AND or OR combinators.

select * from table1 where user in ('a') and END_DATE >'2010-05-22'
Tendayi Mawushe
A: 

Your where clause checks the following:

user in ('a')

is the same as

user = 'a'

You have to add wildcards to check if a username contains an a, or starts with it. I think wildcards depend on your database( don´t know if they are the same everywhere)

It´s not directly your question, just to avoid further ones.

Patrick Säuerl