Results 1 to 13 of 13

Thread: What is wrong with this SQL Statement??(Resolved For MDB Files)

  1. #1

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    What is wrong with this SQL Statement??(Resolved For MDB Files)

    Set DB = OpenDatabase(App.Path & "\Customer Database.mdb")
    Set Records = DB.OpenRecordset("SELECT * FROM Customers WHERE [Site Name] LIKE 'A'%")
    Last edited by BodwadUK; Jun 3rd, 2003 at 08:43 AM.
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  2. #2
    Addicted Member
    Join Date
    Jun 2002
    Posts
    211
    ("SELECT * FROM Customers WHERE [Site Name] LIKE 'A%'")

    Should do it

    Simon

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    try putting the wildcard in the single ticks

  4. #4
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by Simon_R
    ("SELECT * FROM Customers WHERE [Site Name] LIKE 'A%'")

    Should do it

    Simon
    beat me to it

  5. #5

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    Your both wrong that just causes a

    Syntax error in query expression '[Site Name] LIKE 'A'%'.

    error

    Any more suggestions???
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  6. #6
    Fanatic Member doofusboy's Avatar
    Join Date
    Apr 2003
    Posts
    526
    No, they're correct and YOU'RE wrong. Your SQL statement should look like this when it's finished:


    SELECT * FROM Customers WHERE [Site Name] LIKE 'A%'

    That will return all records that have entries in the Site Name column that start with the capital letter A.


    You may want to check if the column should be called:

    Site_Name 'may need to avoid space in column name
    Do canibals not eat clowns because they taste funny?

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Originally posted by doofusboy
    No, they're correct and YOU'RE wrong. Your SQL statement should look like this when it's finished:


    SELECT * FROM Customers WHERE [Site Name] LIKE 'A%'

    That will return all records that have entries in the Site Name column that start with the capital letter A.


    You may want to check if the column should be called:

    Site_Name 'may need to avoid space in column name
    WOW! Talk about the kettle calling the pot black.... Doofus... before you start sligning it around like that, you may want to look up your info first. So far I have not yet seen the right answer.... Bodw is right, putting the % WILL CAUSE A SYNTAX ERROR. That's because he's using an ACCESS DATABASE.... Remember the open database command at the top of his code? He's opening an MDB file, Access. In Access, for what ever reason, MS decided that the wildcard should be a "*", not "%". So, the truly correct answer is:
    1) Change the % to a *
    2) Move the * to inside the tick marks
    That should do it for you.
    * 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??? *

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by techgnome
    WOW! Talk about the kettle calling the pot black.... Doofus... before you start sligning it around like that, you may want to look up your info first. So far I have not yet seen the right answer.... Bodw is right, putting the % WILL CAUSE A SYNTAX ERROR. That's because he's using an ACCESS DATABASE.... Remember the open database command at the top of his code? He's opening an MDB file, Access. In Access, for what ever reason, MS decided that the wildcard should be a "*", not "%". So, the truly correct answer is:
    1) Change the % to a *
    2) Move the * to inside the tick marks
    That should do it for you.
    actually the % wont cause an error.. it will just return an empty recordset.. the error was due to the tick mark placement

  9. #9

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    *Bodwad Snogs techgnome


    YIIIIPPPPIIIIIIIEEEEEEEEEEEE

    *Dances Around the room chanting "Here We Go, Here We Go Here We Go"
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  10. #10
    Fanatic Member doofusboy's Avatar
    Join Date
    Apr 2003
    Posts
    526
    By the way, the word is spelled "s l i n g i n g".

    When use SQL within Access wildcard character is *.

    When using SQL from VB to query an Access database, using wildcard character % is perfectly acceptable. I use it all the time Mr. Smart (__*__).
    Do canibals not eat clowns because they taste funny?

  11. #11

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    You cant because it doesnt work mister smartie pants!!!!
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  12. #12
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by BodwadUK
    You cant because it doesnt work mister smartie pants!!!!
    no he is right... i use % in some SQL statements via ADO that query an access database... and low and behold they always did and still work

  13. #13

    Thread Starter
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176
    Ohhhh OOPS Sorry i got carried away and ran around screaming about nothing in perticular!!!

    My family suggested i make a small padded room for myself. I just dont understand why i need to put the lock on the other side
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

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