Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 passing a field name to an SQL query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-07-26 : 09:47:30
Mark writes "I'm trying to create a search by letting the user select the field name and the search term to a query by creating a variable for the field name. I have no problem passing the search term, but I can't seem to make the field name work. I'm the one who's stumped, but I couldn't seem to find anything regarding this situation. I want to avoid adding a huge if-then or select case statement if possible.

If Request.Form ("search") <> "" Then
Dim strSearchField
Dim strSearchValue
strSearchField = Request.Form ("searchfield")
strSearchValue = Request.Form ("searchvalue")

strSql = "SELECT * FROM Actlayout WHERE '"& strSearchField &"' LIKE '%"& strSearchValue &"%' ORDER BY Company ASC"

Thanks in advance"
   

- Advertisement -