Mehmet Ince
Mehmet Ince

Reputation: 4179

How can I query a table between two dates that can be null?

I have two text box which I can get start & end dates from user. There are 3 condition here.

And finally, What should my query be?

Variables: start_date and end_date

Query: SELECT * FROM kkmail WHERE MAIL_DATE ....

Upvotes: 0

Views: 106

Answers (2)

Noel
Noel

Reputation: 10525

Oracle has LNNVL function to write these type of queries in a concise way, although a little confusing.

SELECT * 
  FROM kkmail 
 WHERE lnnvl(mail_date < @start_date)
   AND lnnvl(mail_date > @end_date);

Demo

Upvotes: 1

juergen d
juergen d

Reputation: 204756

SELECT * FROM kkmail 
WHERE (MAIL_DATE >= @start_date OR @start_date is null)
and (MAIL_DATE <= @end_date OR @end_date is null)

Upvotes: 3

Related Questions