Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Page - SQL Query with WildCard 1

Status
Not open for further replies.

teblack

Programmer
Apr 30, 2004
45
I have an ASP page that I'm attempting to retrieve data from a SQL 2000 DB and display that data on a page. I have built the ado commands, but I'm having problems getting the SQL statement to work when using the wildcard '%'. The code is listed below.

Code:
adoCmd.CommandText = "select * from v_EPAYAdminCompanySearch"

if not Request("empletter") = vbNullString then
	adoCmd.CommandText = adoCmd.CommandText & _
		" where name like '?"
	adoCmd.Parameters.Append adoCmd.CreateParameter("name",  adChar, adParamInput, 5, Request("empletter"))   
	adoCmd.CommandText = adoCmd.CommandText & "%'"
end if

The result that I'm looking for would be the following -

Select * from v_EPAYAdminCompanySearch where name like 'G%'

If you have any ideas, or direction to send me, please let me know.


Thanks in advance for all help with this.

Thanks

TBlack -
 
Perhaps I am oversimplifying this, but couldn't you simply do this:
Code:
adoCmd.CommandText = "select * from v_EPAYAdminCompanySearch"

if not Request("empletter") = vbNullString then
    adoCmd.CommandText = adoCmd.CommandText & _
        " where name like '" & Request("empletter") & "%'"
end if

------------------------------------------------------------------------------------------------------------------------
"I am not young enough to know everything."
Oscar Wilde (1854-1900)
 
Or, could you deal with that in the stored procedure rather than the application?

Rhys
"There are some oddities in the perspective with which we see the world. The fact that we live at the bottom of a deep gravity well, on the surface of a gas-covered planet going around a nuclear fireball 90 million miles away and think this to be normal is obviously some indication of how skewed our perspective tends to be"
DOUGLAS AD
 
When I'm having trouble with the syntax of a SQL statement that runs against MS SQL Server then I like to use the Query Analyzer program to tweak and test the syntax and then, only after it works the way that I like, move back it back into code.
 
Sheco, I think he got the idea of the query correct:

this one

Select * from v_EPAYAdminCompanySearch where name like 'G%'

looks fine to me...is the name a keyword??

i think he is having problems with the ado thing he is using...

-DNG


 
Chopstik, your example worked perfectly. Also, thanks to the rest for the help.

Thanks again,


TBlack -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top