Results 1 to 19 of 19

Thread: sql error in statement (resolved - I GOT IT!)

  1. #1

    Thread Starter
    Addicted Member fenster's Avatar
    Join Date
    Apr 2003
    Location
    Glasgow,Scotland
    Posts
    201

    sql error in statement (resolved - I GOT IT!)

    hi guys..

    im trying to pull all records from my DB (acesss 2000) where

    customername is = string
    orderstatus is = string
    datecomplete is => string
    datecomplete is <= string

    maybe the join is wrong because i need to join table job and transaction by jobid (primary key)


    heres my sql statement
    Code:
        ssql = "SELECT"
        ssql = ssql & " Customer.Name,"
        ssql = ssql & " job.orderdate,"
        ssql = ssql & " Job.PatientName,"
        ssql = ssql & " Job.[Item Description],"
        ssql = ssql & " Job.jobcode,"
        ssql = ssql & " Job.Order_Status,"
        ssql = ssql & " Job.TrayNumber,"
        ssql = ssql & " Job.JobNumber,"
        ssql = ssql & " Job.JobID,"
        ssql = ssql & " Job.custid,"
        ssql = ssql & " Job.jobcode"
        ssql = ssql & " FROM"
        ssql = ssql & " Customer"
        ssql = ssql & " INNER JOIN"
        ssql = ssql & " Job ON Customer.CustID = Job.CustID"
        ssql = ssql & " WHERE (((Customer.Name) = '" & CUSTTOFIND & "'))"
        ssql = ssql & " AND "
        ssql = ssql & " (((Job.Order_Status) = '" & sType & "'))"
        ssql = ssql & " AND "
        ssql = ssql & " (((transaction.datecomplete) => '" & startdate & "'))"
        ssql = ssql & " AND "
        ssql = ssql & " (((transaction.datecomplete) <= '" & enddate & "'))"
        ssql = ssql & " ORDER BY Job.OrderDate;"
    heres the debug print:

    Code:
    SELECT Customer.Name, job.orderdate, Job.PatientName, Job.[Item Description], Job.jobcode, Job.Order_Status, Job.TrayNumber, Job.JobNumber, Job.JobID, Job.custid, Job.jobcode FROM Customer INNER JOIN Job ON Customer.CustID = Job.CustID WHERE (((Customer.Name) = 'Hughes & McHugh (Airdrie)')) AND  (((Job.Order_Status) = 'Invoice')) AND  (((transaction.datecomplete) => '14/08/03')) AND  (((transaction.datecomplete) <= '14/08/03')) ORDER BY Job.OrderDate;
    im getting a missing operator in expression....


    please help if u can

    thanks

    davie.






    the main culprit was => , >= was accepted...


    thanks guys...
    Last edited by fenster; Aug 14th, 2003 at 09:35 AM.

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Probably a parenthesis problem if you ask me... hang on...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Try this :

    VB Code:
    1. strSQLString = "SELECT"
    2.     strSQLString = strSQLString & " Customer.Name,"
    3.     strSQLString = strSQLString & " job.orderdate,"
    4.     strSQLString = strSQLString & " Job.PatientName,"
    5.     strSQLString = strSQLString & " Job.[Item Description],"
    6.     strSQLString = strSQLString & " Job.jobcode,"
    7.     strSQLString = strSQLString & " Job.Order_Status,"
    8.     strSQLString = strSQLString & " Job.TrayNumber,"
    9.     strSQLString = strSQLString & " Job.JobNumber,"
    10.     strSQLString = strSQLString & " Job.JobID,"
    11.     strSQLString = strSQLString & " Job.custid,"
    12.     strSQLString = strSQLString & " Job.jobcode"
    13.    
    14.     strSQLString = strSQLString & " FROM"
    15.     strSQLString = strSQLString & " Customer"
    16.     strSQLString = strSQLString & " INNER JOIN"
    17.     strSQLString = strSQLString & " Job ON Customer.CustID = Job.CustID"
    18.    
    19.     strSQLString = strSQLString & " WHERE (Customer.Name = '" & CUSTTOFIND & "')"
    20.     strSQLString = strSQLString & " AND "
    21.     strSQLString = strSQLString & " (Job.Order_Status = '" & sType & "')"
    22.     strSQLString = strSQLString & " AND "
    23.     strSQLString = strSQLString & " (transaction.datecomplete => '" & startdate & "')"
    24.     strSQLString = strSQLString & " AND "
    25.     strSQLString = strSQLString & " (transaction.datecomplete) <= '" & enddate & "')"
    26.    
    27.     strSQLString = strSQLString & " ORDER BY Job.OrderDate;"
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4

    Thread Starter
    Addicted Member fenster's Avatar
    Join Date
    Apr 2003
    Location
    Glasgow,Scotland
    Posts
    201
    hi plenderj thanks for the quick reply - tried the code u posted :


    2147217900 syntax error (missing operator) in query expression

    could it be that the join for transaction isnt in the sql?

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Your join looks okay. Try reducing the amount of stuff in the query until it finally works and that might pinpoint the problem.
    For example simplify the where clauses...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6

    Thread Starter
    Addicted Member fenster's Avatar
    Join Date
    Apr 2003
    Location
    Glasgow,Scotland
    Posts
    201
    if i rem out lines :
    Code:
      'strSQLString = strSQLString & " AND "
        'strSQLString = strSQLString & " (transaction.datecomplete => '" & startdate & "')"
        'strSQLString = strSQLString & " AND "
        'strSQLString = strSQLString & " (transaction.datecomplete) <= '" & enddate & "')"
    then it works ok...

    the culprit is above..

    im getting the startdate and enddate from textboxes

    Dim startdate As String
    Dim enddate As String

    startdate = txtStart
    enddate = txtEnd

    ive been messing with it all morning but with no luck...

  7. #7
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Ah okay it could be colons or spaces in the dates or something like that.
    Can you paste to here what the start and end dates are ?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  8. #8

    Thread Starter
    Addicted Member fenster's Avatar
    Join Date
    Apr 2003
    Location
    Glasgow,Scotland
    Posts
    201
    14/08/03 startdate
    15/08/03 enddate

    i have the field in the db as date/time (transaction.datecomplete)

    and the date time format as general date
    Last edited by fenster; Aug 14th, 2003 at 06:39 AM.

  9. #9
    New Member
    Join Date
    Jul 2003
    Location
    Bulgaria
    Posts
    3

    Talking

    Hi,
    I think the problem is because you use "transaction" but there is no such table neither after "FROM" nor after "INNER JOIN" clause. The text description of the error (missing operator in expression) might be misleading, it doesn't mean that there is necessarily a missing operator. Anyway, what is the relation of "transaction" to "Job" or "Customer" ? Just add one more "INNER JOIN" (or whatever type of join you need) for table "transaction". On the other side, when I have this kind of problem the error message is something like "The column prefix 'transaction' does not match with a table name or alias name used in the query." ?!?

    ... and I think you don't need these parenthesis in "WHERE" clause...

    Hope this helps

  10. #10

    Thread Starter
    Addicted Member fenster's Avatar
    Join Date
    Apr 2003
    Location
    Glasgow,Scotland
    Posts
    201
    Hi Pikeman,

    heres the relationships:

    cusomer / job are related by cust.id -

    cust.id is the primary key of customer table.

    job / transaction are related by job.id -

    job.id is the primary key for job table.

    what do u mean by adding to the other side?

    could u post something to help me??

    thanks

  11. #11
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Sorry I had left in a bracket above in the where statements :

    VB Code:
    1. strSQLString = strSQLString & " AND "
    2.     strSQLString = strSQLString & " (transaction.datecomplete => '" & startdate & "')"
    3.     strSQLString = strSQLString & " AND "
    4.     strSQLString = strSQLString & " (transaction.datecomplete <= '" & enddate & "')"
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  12. #12

    Thread Starter
    Addicted Member fenster's Avatar
    Join Date
    Apr 2003
    Location
    Glasgow,Scotland
    Posts
    201
    plenderj:

    still get the syntax error in those lines , heres the debug.print:

    Code:
    SELECT Customer.Name, job.orderdate, Job.PatientName, Job.[Item Description], Job.jobcode, Job.Order_Status, Job.TrayNumber, Job.JobNumber, Job.JobID, Job.custid, Job.jobcode FROM Customer INNER JOIN Job ON Customer.CustID = Job.CustID WHERE (Customer.Name = 'Hughes & McHugh (Airdrie)') AND  (Job.Order_Status = 'Invoice') AND  (transaction.datecomplete => '14/08/03') AND  (transaction.datecomplete <= '14/08/03') ORDER BY Job.OrderDate

  13. #13

    Thread Starter
    Addicted Member fenster's Avatar
    Join Date
    Apr 2003
    Location
    Glasgow,Scotland
    Posts
    201
    is this correct :

    still trying!!!

    Code:
        strSQLString = "SELECT"
        strSQLString = strSQLString & " Customer.Name,"
        strSQLString = strSQLString & " job.orderdate,"
        strSQLString = strSQLString & " Job.PatientName,"
        strSQLString = strSQLString & " Job.[Item Description],"
        strSQLString = strSQLString & " Job.jobcode,"
        strSQLString = strSQLString & " Job.Order_Status,"
        strSQLString = strSQLString & " Job.TrayNumber,"
        strSQLString = strSQLString & " Job.JobNumber,"
        strSQLString = strSQLString & " Job.JobID,"
        strSQLString = strSQLString & " Job.custid,"
        strSQLString = strSQLString & " transaction.datecomplete"
        strSQLString = strSQLString & " FROM"
        strSQLString = strSQLString & " Customer"
        strSQLString = strSQLString & " INNER JOIN"
        strSQLString = strSQLString & " Job ON Customer.CustID = Job.CustID"
        strSQLString = strSQLString & " INNER JOIN"
        strSQLString = strSQLString & " Transaction ON Job.jobID = Transaction.jobID"
        strSQLString = strSQLString & " WHERE (Customer.Name = '" & CUSTTOFIND & "')"
        strSQLString = strSQLString & " AND "
        strSQLString = strSQLString & " (Job.Order_Status = '" & sType & "')"
        strSQLString = strSQLString & " AND "
        strSQLString = strSQLString & " (transaction.datecomplete => '" & startdate & "')"
        strSQLString = strSQLString & " AND "
        strSQLString = strSQLString & " (transaction.datecomplete <= '" & enddate & "')"

    still a missing operator!

  14. #14

    Thread Starter
    Addicted Member fenster's Avatar
    Join Date
    Apr 2003
    Location
    Glasgow,Scotland
    Posts
    201
    where have u gone guys?

    we were getting sooooo close

    i bracketed [transaction] think its reserved but still missing operator..

    come on - im all out of ideas here..

  15. #15

    Thread Starter
    Addicted Member fenster's Avatar
    Join Date
    Apr 2003
    Location
    Glasgow,Scotland
    Posts
    201
    im convinced now that i have to use the # operator in dates?

    do u agree?

  16. #16
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Sorry I was wanderign the building. I tried code similar to that myself here and it worked just fine. Granted that was under MySQL, and the dates were back to front, but it worked...
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  17. #17
    Junior Member
    Join Date
    Nov 2002
    Posts
    29
    Try this :

    VB Code:
    1. Dim startdate As String
    2. Dim enddate As String
    3.  
    4. startdate = format$(txtStart, "dd/mm/yyyy")
    5. enddate = format$(txtEnd, "dd/mm/yyyy")
    6.  
    7.  
    8. strSQLString = strSQLString & " AND "
    9. strSQLString = strSQLString & "transaction.datecomplete between startdate and enddate"

    =====================
    Hope that help!

  18. #18
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Originally posted by fenster
    14/08/03 startdate
    15/08/03 enddate

    i have the field in the db as date/time (transaction.datecomplete)

    and the date time format as general date

    My 2 bobs worth... (I had a similar problem). Access uses mm/dd/yy format. Your clause has the day and month back to front.



    Bruce.

  19. #19
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Ooops, didn't realise it was resolved

    What was the problem?

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