Results 1 to 4 of 4

Thread: What's wrong with this SQL code?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    usa
    Posts
    100

    Question

    Where am I going wrong with this code?
    I'm trying to retrieve all records that fall between
    Date1 and Date2.
    Is there a simpler way of writing SQL code like this?

    Code:
    Set rst = dbsRecdata.OpenRecordset("SELECT rechdr.recno, RecHdr.ponum," _
                & " RecHdr.daterecvd, RecLine.ItemNum, RecLine.Descrip, RecLine.QtyRecvd, RecLine.UnitPrice" _
                & " FROM RecHdr, RecLine" _
                & " WHERE RecHdr.recno = RecLine.recno" _
                & " and RecHdr.DateRecvd >= " & Date1 _
                & " And <= " & Date2 & "" _
                & " ORDER BY RecHdr.recno ASC,RecLine.descrip ASC", dbOpenDynaset)

  2. #2
    Member
    Join Date
    Nov 2000
    Location
    Brisbane, Australia
    Posts
    44

    Thumbs up

    Yes yenni, there is the SQL command, "BETWEEN":

    Set rst = dbsRecdata.OpenRecordset("SELECT rechdr.recno, RecHdr.ponum," _
    & " RecHdr.daterecvd, RecLine.ItemNum, RecLine.Descrip, RecLine.QtyRecvd, RecLine.UnitPrice" _
    & " FROM RecHdr, RecLine" _
    & " WHERE RecHdr.recno = RecLine.recno" _
    & " and RecHdr.DateRecvd BETWEEN #" & Date1 _
    & "# And #" & Date2 & "#" _
    & " ORDER BY RecHdr.recno ASC,RecLine.descrip ASC", dbOpenDynaset)

    Dates need to appear like this: #24/11/2000# in an SQL query, that's why I've included them in mine.

    I'm not sure this query works though - I don't have your tables to test it on and I'm not really in the mood to create a test Db. My reading through makes me think it should though.
    Boring signature included.

    VB6 SP3.

  3. #3
    Member
    Join Date
    Nov 2000
    Location
    Brisbane, Australia
    Posts
    44

    Exclamation

    Sorry Yenni,

    I'm from Australia, it's hard to slip from our date format to the US one. The actual date format SQL requires is #11/24/2000#.

    And yes it is the 24th here!
    Boring signature included.

    VB6 SP3.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jan 2000
    Location
    usa
    Posts
    100
    Thanks for yours ans batleycr, I'll give a try.
    Actually, I'm from Jamaica, and we use the same date
    format as you, i.e dd/mm/yy.
    By the way, take it easy with our guys down there,
    o.k? (cricket, that is)

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