Results 1 to 9 of 9

Thread: sql statement needed

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    98

    sql statement needed

    Been playing with this one and havent had any luck..
    How would you write an sql statement to delete any dates previous to today's date.
    I've tried the following

    ie
    sql="delete from MyTable where TheDate<" & date
    sql="delete from MyTable where TheDate<" & "#" & date & "#"
    sql="delete from MyTable where TheDate<" & "'" & date & "'"

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    SQL Server or Access?
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    If access:

    sql="DELETE FROM [MyTable] WHERE [TheDate] < #" & date & "#"

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    98

    not yet

    I tried that one as well...
    This is an Access db.
    sql="delete * from [mytable]" deletes all records as expected but I only want to remove dates that have already passed.
    sql=delete * from [mytable] where [thedate]<" & date
    sql=delete * from [mytable] where [thedate]<" & "#" & date & "#"
    sql=delete * from [mytable] where [thedate]<#" & date &"#"

    have all been tried unsuccessfully.....
    anyone? thx

  5. #5
    Hyperactive Member
    Join Date
    Nov 2002
    Location
    india
    Posts
    418
    hi,

    try this

    db.execute "delete * from [myTable] where [Datefield]<#" & date & "#"

  6. #6
    Fanatic Member
    Join Date
    Oct 2001
    Location
    Earth
    Posts
    762

    Cool

    hi try this


    con.execute "delete from table where dt < #" & now() & "#"

    before it confirm that ur datafiled name is not date

    if ur datafiled name is date then u can't delete records..
    i hope u confirm it

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Posts
    98

    still no go

    The Date field is called TheDate just for that reason.
    I've tried all the suggestion and still can not get dates < todays date to delete from the table.

  8. #8
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Originally posted by techgnome
    SQL Server or Access?
    What is a variable name for your date parameter?
    Could you post your code here?

  9. #9
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390
    are you running the SQL form inside Access???

    I just ran this :

    DoCmd.RunSQL ("delete * from test where thedate < #" & Date & "#")


    (test was my table)

    and it worked fine..deleted everything before today
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width