Click to See Complete Forum and Search --> : SQL syntax
casox
Dec 28th, 1999, 09:45 PM
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
RogerH
Dec 28th, 1999, 10:36 PM
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)
casox
Dec 28th, 1999, 10:53 PM
It works! Imagine that. Thanks so much.
casox
JHausmann
Dec 30th, 1999, 02:42 AM
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).
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.