|
-
Dec 28th, 1999, 10:45 PM
#1
Thread Starter
Lively Member
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
-
Dec 28th, 1999, 11:36 PM
#2
Lively Member
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)
-
Dec 28th, 1999, 11:53 PM
#3
Thread Starter
Lively Member
It works! Imagine that. Thanks so much.
casox
-
Dec 30th, 1999, 03:42 AM
#4
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|