Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. A really stupid problem with SQL

A really stupid problem with SQL

Scheduled Pinned Locked Moved Database
questiondatabasehelptutorial
17 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dan Pomerchik
    wrote on last edited by
    #1

    Well , I wrote a little app in VB that queries a table. I used DAO.I created a SQL generator that builds up a statement. But somehow only if I use * instead of % it works. For example , if i execute

    select * from Phonebook where Firstname like 'M*'

    I will get the appropriate records beginning with M. but if i write:

    select * from Phonebook where Firstname like 'M%'

    than all i get is an empty recordset! Why is that?! i remember that i used % before and it worked just fine. maybe someone knows what is the problem? thx!

    J C D 3 Replies Last reply
    0
    • J James T Johnson

      % is standard SQL, however Access (and thus DAO) uses *. I got bit by the opposite problem when I made the transition from DAO to ADO/SQL Server James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

      D Offline
      D Offline
      Dan Pomerchik
      wrote on last edited by
      #2

      Ahh thanks. And what about ADO ? Does it work with % or must use * too ?

      J M 2 Replies Last reply
      0
      • D Dan Pomerchik

        Well , I wrote a little app in VB that queries a table. I used DAO.I created a SQL generator that builds up a statement. But somehow only if I use * instead of % it works. For example , if i execute

        select * from Phonebook where Firstname like 'M*'

        I will get the appropriate records beginning with M. but if i write:

        select * from Phonebook where Firstname like 'M%'

        than all i get is an empty recordset! Why is that?! i remember that i used % before and it worked just fine. maybe someone knows what is the problem? thx!

        J Offline
        J Offline
        James T Johnson
        wrote on last edited by
        #3

        % is standard SQL, however Access (and thus DAO) uses *. I got bit by the opposite problem when I made the transition from DAO to ADO/SQL Server James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

        D 1 Reply Last reply
        0
        • D Dan Pomerchik

          Ahh thanks. And what about ADO ? Does it work with % or must use * too ?

          J Offline
          J Offline
          James T Johnson
          wrote on last edited by
          #4

          That I'm not sure about, I think it uses * for Access and % for others, but I'm not sure as I haven't done any ADO on Access. Oddly that was one combination I was able to avoid. James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

          M 1 Reply Last reply
          0
          • J James T Johnson

            That I'm not sure about, I think it uses * for Access and % for others, but I'm not sure as I haven't done any ADO on Access. Oddly that was one combination I was able to avoid. James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

            M Offline
            M Offline
            Mazdak
            wrote on last edited by
            #5

            James T. Johnson wrote: but I'm not sure as I haven't done any ADO on Access I used it.You have to use % .:) Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

            1 Reply Last reply
            0
            • D Dan Pomerchik

              Ahh thanks. And what about ADO ? Does it work with % or must use * too ?

              M Offline
              M Offline
              Mazdak
              wrote on last edited by
              #6

              Dan Pomerchik wrote: And what about ADO ? Does it work with % or must use * too ? In ADO You have to use % .:) Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

              D 1 Reply Last reply
              0
              • M Mazdak

                Dan Pomerchik wrote: And what about ADO ? Does it work with % or must use * too ? In ADO You have to use % .:) Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

                D Offline
                D Offline
                Dan Pomerchik
                wrote on last edited by
                #7

                Oh this is crap, every time you have to use a different character :omg: Why can't they just SET a STANDARD and USE it in all db's/platforms/etc.!? Anyway thanks guys, good to have some people who help :-)

                L N J 3 Replies Last reply
                0
                • D Dan Pomerchik

                  Oh this is crap, every time you have to use a different character :omg: Why can't they just SET a STANDARD and USE it in all db's/platforms/etc.!? Anyway thanks guys, good to have some people who help :-)

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Dan Pomerchik wrote: Why can't they just SET a STANDARD and USE it in all db's/platforms/etc.!? How do you think they keep us on our feet? :)

                  1 Reply Last reply
                  0
                  • D Dan Pomerchik

                    Oh this is crap, every time you have to use a different character :omg: Why can't they just SET a STANDARD and USE it in all db's/platforms/etc.!? Anyway thanks guys, good to have some people who help :-)

                    N Offline
                    N Offline
                    Nick Parker
                    wrote on last edited by
                    #9

                    Dan Pomerchik wrote: Why can't they just SET a STANDARD and USE it in all db's/platforms/etc.!? How do you think they keep us on our feet? :) Don't you hate it when you forget to log on with the message boards? Nick Parker

                    D 1 Reply Last reply
                    0
                    • D Dan Pomerchik

                      Oh this is crap, every time you have to use a different character :omg: Why can't they just SET a STANDARD and USE it in all db's/platforms/etc.!? Anyway thanks guys, good to have some people who help :-)

                      J Offline
                      J Offline
                      James T Johnson
                      wrote on last edited by
                      #10

                      There is a standard, %, I don't know if its in writing but everything I've seen except Access uses it :) Access (and DAO) is used on windows only, so it made sense to use * as the 'match anything wildcard' which is what windows uses. James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

                      1 Reply Last reply
                      0
                      • D Dan Pomerchik

                        Well , I wrote a little app in VB that queries a table. I used DAO.I created a SQL generator that builds up a statement. But somehow only if I use * instead of % it works. For example , if i execute

                        select * from Phonebook where Firstname like 'M*'

                        I will get the appropriate records beginning with M. but if i write:

                        select * from Phonebook where Firstname like 'M%'

                        than all i get is an empty recordset! Why is that?! i remember that i used % before and it worked just fine. maybe someone knows what is the problem? thx!

                        C Offline
                        C Offline
                        Carlos Antollini
                        wrote on last edited by
                        #11

                        Because * replace the rest of characters and % replace only One Character.... For Example if you have a table with the following records Mother My Mine M* get all the records and M% only the Second Record... Best Regards Carlos Antollini. Sonork ID 100.10529 cantollini

                        M N D 3 Replies Last reply
                        0
                        • C Carlos Antollini

                          Because * replace the rest of characters and % replace only One Character.... For Example if you have a table with the following records Mother My Mine M* get all the records and M% only the Second Record... Best Regards Carlos Antollini. Sonork ID 100.10529 cantollini

                          M Offline
                          M Offline
                          Mazdak
                          wrote on last edited by
                          #12

                          :eek: :eek: Carlos Antollini wrote: M% only the Second Record... No,Carlos.Thats not true.'%' get all of them too.:) Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

                          C 1 Reply Last reply
                          0
                          • M Mazdak

                            :eek: :eek: Carlos Antollini wrote: M% only the Second Record... No,Carlos.Thats not true.'%' get all of them too.:) Mazy "The path you tread is narrow and the drop is shear and very high, The ravens all are watching from a vantage point near by, Apprehension creeping like a choo-train uo your spine, Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd

                            C Offline
                            C Offline
                            Carlos Antollini
                            wrote on last edited by
                            #13

                            Mazy It's True... :-O I found the following: Kind of match Pattern Match (returns True) No match (returns False) Multiple characters a*a aa, aBa, aBBBa *ab* abc, AABB, Xab aZb, bac Special character a[*]a a*a aaa Multiple characters ab* abcdefg, abc cab, aab Single character a?a aaa, a3a, aBa aBBBa Single digit a#a a0a, a1a, a2a aaa, a10a Range of characters [a-z] f, p, j 2, & Outside a range [!a-z] 9, &, % b, a Not a digit [!0-9] A, a, &, ~ 0, 1, 9 Combined a[!b-m]# An9, az0, a99 abc, aj0 Best Regards....;) Carlos Antollini. Sonork ID 100.10529 cantollini

                            1 Reply Last reply
                            0
                            • C Carlos Antollini

                              Because * replace the rest of characters and % replace only One Character.... For Example if you have a table with the following records Mother My Mine M* get all the records and M% only the Second Record... Best Regards Carlos Antollini. Sonork ID 100.10529 cantollini

                              N Offline
                              N Offline
                              Nick Parker
                              wrote on last edited by
                              #14

                              In T-SQL (SQL Server) the % character will do a wildcard beyond that point(all characters)

                              'boo%' results in book, books, boobs....

                              the _ character will act as a single wildcard

                              'b_ok' will find anything for the second character(i.e. - book). Nick Parker

                              1 Reply Last reply
                              0
                              • C Carlos Antollini

                                Because * replace the rest of characters and % replace only One Character.... For Example if you have a table with the following records Mother My Mine M* get all the records and M% only the Second Record... Best Regards Carlos Antollini. Sonork ID 100.10529 cantollini

                                D Offline
                                D Offline
                                Dan Pomerchik
                                wrote on last edited by
                                #15

                                Oh thanks a lot , that explains everything :-) :-) - Dan "Intel inside - Idiot outside"

                                1 Reply Last reply
                                0
                                • N Nick Parker

                                  Dan Pomerchik wrote: Why can't they just SET a STANDARD and USE it in all db's/platforms/etc.!? How do you think they keep us on our feet? :) Don't you hate it when you forget to log on with the message boards? Nick Parker

                                  D Offline
                                  D Offline
                                  Dan Pomerchik
                                  wrote on last edited by
                                  #16

                                  Nick Parker wrote: How do you think they keep us on our feet? :-) Nick Parker wrote: Don't you hate it when you forget to log on with the message boards? Actually, I'm allowing those cookies so I don't have to log on :-) Btw, I tried to change the default password I got and somehow it won't change. Does anyone knows something about it ? - Dan "Intel inside - Idiot outside"

                                  1 Reply Last reply
                                  0
                                  • D Dan Pomerchik

                                    Well , I wrote a little app in VB that queries a table. I used DAO.I created a SQL generator that builds up a statement. But somehow only if I use * instead of % it works. For example , if i execute

                                    select * from Phonebook where Firstname like 'M*'

                                    I will get the appropriate records beginning with M. but if i write:

                                    select * from Phonebook where Firstname like 'M%'

                                    than all i get is an empty recordset! Why is that?! i remember that i used % before and it worked just fine. maybe someone knows what is the problem? thx!

                                    D Offline
                                    D Offline
                                    Dan Pomerchik
                                    wrote on last edited by
                                    #17

                                    Dammit! I'm totaly confused now! Someone said that % is for one char and * for all. Someone else said % is standard and * for DAO/ADO. What happening!? :-) - Dan "Intel inside - Idiot outside"

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups