Click to See Complete Forum and Search --> : [RESOLVED] Delete range of entries from database!!


priyam
09-15-2008, 06:56 AM
Hi All

I am creating a database archiving tool,in which a user can delete all the data before a date he would specify.But the problem is i am not able to create a delete query which can delete a range of data.

I had created the following query

<%
pdt=request.form("prevdate") 'contains the date starting from which data has to be deleted
cdt=request.form("currdate") 'contains the date till which data has to be deleted
' declaring variables
' not neccesary but a good habit
Dim DataConn
Dim CmdDeleteRecord
Dim MYSQL

Set DataConn = Server.CreateObject("ADODB.Connection")


Set CmdDeleteRecord = Server.CreateObject("ADODB.Recordset")

' The line below shows how to use a system DSN instead of a DNS-LESS connection
' DataConn.Open "DSN=System_DSN_Name"
DataConn.Open "DBQ=" & Server.Mappath("../fpdb/taxireq.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};"

MYSQL = "DELETE FROM Request_detail WHERE Repdate between '" & pdt &"' and '" & cdt &"'"

CmdDeleteRecord.Open MYSQL, DataConn

' closing objects and setting them to nothing
' not neccesary but a good habit
DataConn.Close
Set DataConn = Nothing
%>


please suggest any changes so that i can delete a range of data from the database

Thank You!!

Bullschmidt
09-16-2008, 01:45 AM
Perhaps change this:
MYSQL = "DELETE FROM Request_detail WHERE Repdate between '" & pdt &"' and '" & cdt &"'"

To be more like this instead (# instead of ' around dates for an Access database):
MYSQL = "DELETE FROM Request_detail WHERE Repdate between #" & pdt &"# and '# & cdt &"#"

TheBearMay
09-16-2008, 07:38 AM
Please don't cross post.

priyam
09-16-2008, 02:43 PM
I did not do it intentionally,actually i was unable to delete this thread because i couldn't find the option to delete it...so i marked it as RESOLVED.
I figured out after posting on this forum that this query is SQL related and should be posted in that forum.