Home > SQL Development > Help with SELECT LIKE, variables, and wildcards

Help with SELECT LIKE, variables, and wildcards



<i><b>Originally posted by : J.R. Porter (jar@nauticom.net)</b></i><br />Is it possible to put a variable into an SQL query in ASP? Suppose I have the following...<br /><br />SELECT * FROM Archive WHERE lname LIKE 'C%'<br /><br />This would get every last name that started with the letter C. But suppose I want to replace C with a variable but keep the wildcard(%). Is this possible? Any help would be appriciated.<br />

    
Guest


<i><b>Originally posted by : Tridus (tridus@inforamp.net)</b></i><br />yes... you can build the sql query into a variable and then you can add it into the variable... I do something like this:<br /><br />dim sqlstr, searchvar<br /><br />' this is the variable you want to search for<br />searchvar = "C"<br /><br />' this is your query<br />sqlstr = "SELECT * FROM archive WHERE lname LIKE '" & searchvar & "%'" (which will look like this: "SELECT * FROM archive WHERE lname LIKE 'C%'")<br /><br />That will simply stick the C in where searchvar is. Change searchvar, and the item changes. This is really good with request.form("blah") or request.querystring("blah") to just grab the variables off a form.

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved