Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete * from table where date between ..... 1

Status
Not open for further replies.

richand1

Programmer
Feb 4, 2004
88
GB
Hi all

I know what's in the subject is far from being the correct way to do this as I did this a few months ago and forgot to save the script!

Basically, I've got a SQL datestamp applied to all records in a table. Structyre of the date is standard SQL:

2005-06-08 07:00:00

I need to delete records from this table that are between two dates, regardless of the time. I've been messing around with and I think using that is how I did it before but I can't, for the life of me, get it right!

Please help, thanks in advance!

Rich
 
Say you want to delete all dates between 1st July and 20th July (inclusive):

Code:
DELETE table
WHERE date >= '20050701'
  AND date < '20050721'

--James
 
Hi James

It returns this conversion error mate:

"Arithmetic overflow error converting expression to data type smalldatetime.
 
Is your date column smalldatetime or datetime?
What values are you using in your DELETE statement?

--James
 
Sorry James, I left out the apostrophies around the values; tried to rush it. All sorted now.

Thank you very much, for help and quick response.

Rich
 
You could also use the between clause too. (as per your original post)

Code:
DELETE sds_ils_loan
WHERE  lastupdatedate between '2002-07-01' 
                               and '2002-07-21'

Regards,
AA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top