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

Thread: LIKE statement

  1. #1
    Join Date
    Aug 2001
    Location
    The Netherlands, near germany
    Posts
    42

    LIKE statement

    I want to make a LIKE statement with a variable, when I do it like this, it doesn't work:
    tSQL = "Select * from klantenbestand WHERE Company_Name LIKE ''" & searchrel

    What is the right statement with a variable??

    Remco Ploeg
    [email protected]

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: LIKE statement

    tSQL = "Select * from klantenbestand WHERE Company_Name LIKE " & searchrel
    or
    tSQL = "Select * from klantenbestand WHERE Company_Name LIKE '%" & searchrel & "%'"
    or
    tSQL = "Select * from klantenbestand WHERE Company_Name LIKE ''%" & searchrel & "%''"




    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Micahel
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    Aug 2001
    Location
    The Netherlands, near germany
    Posts
    42

    Re: LIKE statement

    this is working, but now he shows the records that contains the variable. For example
    variable = k
    kampa company
    esko company
    He display the two record because there is a k in. I want only the first letter

    Remco Ploeg
    [email protected]

  4. #4
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: LIKE statement

    This should do the trick

    tSQL = "Select * from klantenbestand WHERE Company_Name LIKE '" & searchrel & "%'"


    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

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