CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Like command

  1. #1
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    53

    Like command

    Hi,

    I use following SQL-String to get all eMails in my Access Database belonging to the same domain:

    sql.Format( "SELECT login, passwort, email FROM Accountdaten WHERE email Like '*%s*'", domain );

    But for some reason LIKE doesn't work. Can u tell me where the problem is? I have MDAC SP1 installed.

    Thanx in advanced

    Karsten


  2. #2
    Join Date
    Sep 1999
    Location
    NJ
    Posts
    1,299

    Re: Like command

    In SQL, the wildcard character is not "*", it's "%". SO, to say "every domain with 'microsoft' in it, you'd write it as:
    SELECT login, passwort, email FROM Accountdaten WHERE email Like '%micorosoft%'"

    Of course, using th Format() complictes this:

    sql.Format( "SELECT login, passwort, email FROM Accountdaten WHERE email Like '%%%s%%'", domain );




    Two %s become one % when passed through printf/format


    Truth,
    James
    http://www.NJTheater.com
    http://www.NJTheater.com/JamesCurran

  3. #3
    Join Date
    Apr 1999
    Location
    Germany
    Posts
    53

    Re: Like command

    Hi,

    jeah, that really works. Thanx a lot.

    But I still have another question. Ist there a command for searching all fields at one time for a keyword?

    at the moment I have to do it with Like for each field. Ist there another command available which can do this on it's own? If yes, can u give me an example?

    Thanx in advance

    Karsten


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

Featured