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

Select Syntax

Status
Not open for further replies.

mot98

MIS
Jan 25, 2002
647
CA
Hi All,

I need to run a Select statement using a variable. The code looks like the following:

<%
varCity = Request.QueryString (&quot;varCity&quot;)
varBusiness = Request.QueryString (&quot;varBusiness&quot;)
Dim oRSb
set oRSb=Server.CreateObject(&quot;ADODB.Recordset&quot;)
sqltext = &quot;SELECT Company, BusinessStreet, BusinessCity, BusinessPhone, WebPage &quot;
sqltext = sqltext & &quot; FROM Contacts WHERE BusinessCity = '&quot; & varCity & &quot;';&quot;
sqltext = sqltext & &quot; AND '&quot; & varBusiness & &quot;' = true &quot;
oRSb.Open sqltext, &quot;DSN=EHome&quot;
oRSb.MoveFirst
%>


varBusiness is a variable refering to a column in my table. I need it to check to see if the column has a &quot;true&quot; value before printing it in the table.

With this code I am getting an error saying Characters found after end of SQL statement

Can anyone show me the correct code to get this to work?

Thanks,
mot98
[pc]

&quot;Every day I learn something new, and forget 10 things I learned long ago!&quot;
 
Take out the ; after varCity... ; indicates the end of the sql statement. Also, remove the single quotes from around your column name varBusiness.

<%
varCity = Request.QueryString (&quot;varCity&quot;)
varBusiness = Request.QueryString (&quot;varBusiness&quot;)
Dim oRSb
set oRSb=Server.CreateObject(&quot;ADODB.Recordset&quot;)
sqltext = &quot;SELECT Company, BusinessStreet, BusinessCity, BusinessPhone, WebPage &quot;
sqltext = sqltext & &quot; FROM Contacts WHERE BusinessCity = '&quot; & varCity & &quot;'&quot;
sqltext = sqltext & &quot; AND &quot; & varBusiness & &quot; = true &quot;
oRSb.Open sqltext, &quot;DSN=EHome&quot;
oRSb.MoveFirst
%>
 
Hi,
It looks like you are adding a ';' before you finish your where clause...

The line is
Code:
sqltext = sqltext & &quot; FROM Contacts WHERE BusinessCity = '&quot;

& varCity & &quot;';&quot;

Code:
 sqltext = sqltext & &quot; AND '&quot; & varBusiness & &quot;' = true &quot;

Move it to after the last criterion and it should work..

[profile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top