user1647667
user1647667

Reputation: 1309

Removing Date within the Date Range

Here is the sample data

enter image description here

How can I remove the date if the date is between the date range below?

The result should only display
21 Jan 2015

Upvotes: 0

Views: 492

Answers (4)

Anil kumar
Anil kumar

Reputation: 101

DELETE FROM tableName WHERE date BETWEEN '01/26/2015' AND '01/27/2015'

Upvotes: 0

Sigee
Sigee

Reputation: 352

Try this format:

DELETE FROM table WHERE date = '2015-01-21'

or

DELETE FROM table WHERE date > '2015-01-20' AND date < '2015-01-22';

Maybe the date is not exactly '2015-01-21'.

Upvotes: 0

Tharif
Tharif

Reputation: 13971

Use between to delete rows between the given dates :

DELETE FROM date1
WHERE        (date BETWEEN '01/26/2015' AND '01/27/2015')

Now values other than 21st Jan 2015 will get deleted :

use select query to view your result.

Output :01/21/2015

Upvotes: 1

Eric
Eric

Reputation: 5743

If you just want to display, use NOT EXISTS() in the select

SELECT Date FROM Dates d 
WHERE NOT EXISTS(SELECT * FROM DateRange WHERE d.Date BETWEEN StartDate AND EndDate)

If you need to delete the records

DELETE FROM Dates d 
WHERE EXISTS(SELECT * FROM DateRange WHERE d.Date BETWEEN StartDate AND EndDate)

Upvotes: 0

Related Questions