Results 1 to 21 of 21

Thread: SQL Query question

  1. #1

    Thread Starter
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519

    Question SQL Query question

    Can anyone tell me why this sql string gives me an error?

    VB Code:
    1. "SELECT * FROM WorkOrders WHERE CustomerRefNumber = 'MM-0000001' AND JobCompleted = '1'"

    I am using a MSA 2000 db and ADO.

    I get an error of "Data type mismatch"

    Thanks,
    Rudy -
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  2. #2
    Fanatic Member
    Join Date
    Feb 2003
    Location
    Los Angeles, CA
    Posts
    681
    maybe because the [JobCompleted] field is declared as some sort of numeric in the database. if it is, take off the quotes around the value:
    VB Code:
    1. "SELECT * FROM WorkOrders WHERE CustomerRefNumber = 'MM-0000001' AND JobCompleted = 1"

  3. #3

    Thread Starter
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    The jobcompleted field is a checkbox. I have tried it with a 0 (=false) and a False parameter. I get the same error...

    Confusing...

    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  4. #4
    Fanatic Member
    Join Date
    Feb 2003
    Location
    Los Angeles, CA
    Posts
    681
    i'm affraid i dont get the idea then. when you submit the query, you have to put in the name of the field as it is declared in the database (the 'column' name), not the name of the checkbox...

  5. #5

    Thread Starter
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    Yea. "JobCompleted" is the field. Its datatype is a checkbox (yes/no).


    This is the sql generated by MSA

    SELECT *
    FROM WorkOrders
    WHERE (((WorkOrders.CustomerRefNumber)="MM-0000001") AND ((WorkOrders.JobCompleted)=True));
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  6. #6

    Thread Starter
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    ***Bump***
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  7. #7

    Thread Starter
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    I think it is how I am using the "AND" to select based on 2 different values. Can someone verify that the SQL string is correct?



    Thanks,
    Rudy
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  8. #8
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Try:

    "SELECT * FROM WorkOrders WHERE CustomerRefNumber = 'MM-0000001' AND JobCompleted = -1"
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  9. #9

    Thread Starter
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    Nope, that didn't work either.....

    I tried another field from the table and get the same error... Is the SQL string correct?? It can't be...



    Rudy
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  10. #10
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    What type of field is CustomerRefNumber?
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  11. #11

    Thread Starter
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    CustomerRefNumber is a String.
    JobCompleted is Yes/No.

    I tried it with just CustomerRefNumber and it works fine.

    VB Code:
    1. SELECT * FROM WorkOrders WHERE CustomerRefNumber = '" & CustomerNumber & "'"

    Then I tried these and they didn't work...

    VB Code:
    1. "SELECT * FROM WorkOrders WHERE JobCompleted = '0'"
    2. and
    3. "SELECT * FROM WorkOrders WHERE JobCompleted = '1'"
    4. and
    5. "SELECT * FROM WorkOrders WHERE JobCompleted = '-1'"
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  12. #12

    Thread Starter
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    GOT IT! Wew, finally..

    The key is the "True" statement.. I hade 'True' and it needed to be True without the quotes....


    VB Code:
    1. "SELECT * FROM WorkOrders WHERE CustomerRefNumber = '" & CustomerNumber & "' AND JobCompleted = True"

    This a new one to me.... I think. I don't remember ever having this problem before..

    Oh-well Thank to Mc Brain and Radum for the help..

    Rudy
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  13. #13

    Thread Starter
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    I am getting even more confused...

    It seems that I can only have the quotes around the first value..

    VB Code:
    1. "SELECT * FROM WorkOrders WHERE CustomerRefNumber = '" & CustomerNumber & "' AND Status = " & WorkOrderStatus & " AND JobCompleted = True "
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  14. #14
    Fanatic Member
    Join Date
    Feb 2003
    Location
    Los Angeles, CA
    Posts
    681
    aw jeez... isnt it funny how each sql dialect loves to mess around with the syntax for these boolean values... a couple of years ago i spent a few good days to figure out a syntax like
    VB Code:
    1. myField = .TRUE.
    when running a sql statement a foxpro database

  15. #15

    Thread Starter
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    So let me get this straight..

    Time/Date fields are souronded by ##
    String/Number fields are souronded by ''
    Boolean/True-False as souronded by ..

    What else?

    Is this an ADO thing? I Never had this problem with RDO...

    Rudy
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

  16. #16
    Fanatic Member
    Join Date
    Feb 2003
    Location
    Los Angeles, CA
    Posts
    681
    sorry tom dissapoint you, but honestly i dont know all the syntax combinations myself either. that thing with dots works for the foxpro odbc driver, but i doubt it works for something else. im almost sure it doesnt work for ms access in fact. i only worked with sql lately, so trust anybody else giving answers on that. i kinda bailed out of the thread at the point i saw other answers for you...

  17. #17
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by RudyL
    So let me get this straight..

    Time/Date fields are souronded by ##
    String/Number fields are souronded by ''
    Boolean/True-False as souronded by ..

    What else?

    Is this an ADO thing? I Never had this problem with RDO...

    Rudy
    Number fields should not be surrounded at all.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  18. #18
    Addicted Member
    Join Date
    Oct 2002
    Posts
    174
    IN ACCESS,
    Time/Date fields are souronded by ##
    String/Number fields are souronded by ''
    Boolean/True-False as souronded by ..

    IN MYSQL

    Time/Date fields are souronded by ''
    String/Number fields are souronded by ''
    Boolean/True-False as souronded by ..

  19. #19
    Lively Member
    Join Date
    Sep 2002
    Posts
    89
    If it's a string, wrap single quotes around it. If it's a number, don't use quotes. If it is a boolean value, pass it in as a number (True = 1, False = 0) with no quotes around it.

    Passing in True or False will work against an Access database, but not against many others. SQL Server requires it ot be 1 or 0.

    Don't forget that CInt(True) in VB6 returns -1, not 1, so you might want to use Abs(CInt(BooleanVariable)) to make sure it works.

    - gaffa

  20. #20
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    Originally posted by gaffa
    ...

    Don't forget that CInt(True) in VB6 returns -1, not 1, so you might want to use Abs(CInt(BooleanVariable)) to make sure it works.
    Or just
    VB Code:
    1. -CInt(BooleanVariable)
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  21. #21

    Thread Starter
    Frenzied Member RudyL's Avatar
    Join Date
    Mar 2001
    Location
    Chicago
    Posts
    1,519
    Thanks alot for all the help.. and info.

    Rudy
    10 different ways to skin a cat and amazingly enough each and every one has the same result, the cat gets skinned! The same can be applied to code, so be nice and accept each others "preferences".

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