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
Printable View
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
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)
It works! Imagine that. Thanks so much.
casox
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).