Results 1 to 4 of 4

Thread: SQL syntax

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Oak Creek, WI, USA
    Posts
    92

    Post

    How do I insert a variable into an SQL LIKE statement? ex.

    SELECT * FROM Issues WHERE Issue LIKE '%[variable]%' ?

    I want to match a variable pattern occuring anywhere in a string.

    Thanks,

    casox

  2. #2
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    You will have to 'build' your SQL statement

    VB:
    SQLString = "SELECT * FORM Issues WHERE Issue LIKE '%" & variable & "%'"

    Use e.q. OpenRecordSet with this SQLString

    MS SQL-Server:
    SELECT @SQLString = 'SELECT * FORM Issues WHERE Issue LIKE ''%' & @variable & '%'''
    EXEC(@SQLString)


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 1999
    Location
    Oak Creek, WI, USA
    Posts
    92

    Post

    It works! Imagine that. Thanks so much.

    casox

  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    Problem with what you're doing is that it's gonna be slow. Wildcarding on both ends of the string sends, usually, the DBMS into tablescan reads. If, however, you have an index _and_ a wildcard one side, the DBMS _can_ do index reads (depending on the state of your index pages, can be orders of magnitude faster).

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