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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP and SQL Error - expected end of statement

Status
Not open for further replies.

vistor

Technical User
Dec 22, 2000
164
US
Hi,

my query is below.


If Request("query_type") = "name" Then
sqlQ = sqlQ & " WHERE Employee.last_name = " Request("txtlast_name"

ElseIf Request("query_type") = "location" Then
sqlQ = sqlQ & " WHERE Employee.location_id = " & CInt(Request("txtquery")) & " ORDER BY Employee.last_name, Employee.first_name"

ElseIf Request("query_type") = "dept" Then
sqlQ = sqlQ & " WHERE Employee.department_id = " & CInt(Request("txtquery")) & " ORDER BY Employee.last_name, Employee.first_name"
End If

The location and dept return data from the db just fine. The name does not. When the user inputs a name on the form, this error is generated:

Expected end of statement

sqlQ = sqlQ & " WHERE Employee.last_name = " Request("txtlast_name")
---------------------------------------------^

below is the code from the input on the form, :

<input type=&quot;hidden&quot; name=&quot;query_type&quot; value=&quot;name&quot;>
<input type=&quot;text&quot; name=&quot;txtlast_name&quot; size=&quot;20&quot; value= &quot;&quot; tabindex=&quot;1&quot;>


Any idea on why the last name wont search?

 
First of all a bracket is missing(after &quot;txtlast_name&quot; ). Probably you didn't copied on the thread. but the problem is because you having the criteria after a string you should put it between single quotes like this

If Request(&quot;query_type&quot;) = &quot;name&quot; Then
sqlQ = sqlQ & &quot; WHERE Employee.last_name = '&quot; Request(&quot;txtlast_name&quot;) & &quot;'&quot;

Regards,
Durug
 
Durug,

Still getting error mwssage:
sqlQ = sqlQ & &quot; WHERE Employee.last_name = '&quot; Request(&quot;txtlast_name&quot;) & &quot;'&quot;
----------------------------------------------^
Let me see if I read your quote sequence correct:
WHERE Employee.last_name = single quote double quote
Request(&quot;txtlast_name&quot;) & double quote single quote double quote


CDWD
 
I'm really dreaming :)
sqlQ = sqlQ & &quot; WHERE Employee.last_name = '&quot; & Request(&quot;txtlast_name&quot;) & &quot;'&quot;

Sorry. It should work now
Durug
 
The corect sequence
WHERE Employee.last_name = single quote double quote &
Request(&quot;txtlast_name&quot;) & double quote single quote double quote
 
Durug,

Thank you so much, it is working fine now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top