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

Using a variable in an SQL statement

Status
Not open for further replies.

campbemr

Technical User
Aug 16, 2001
19
US
This is the code I use everything is defined:

Function CountAds(CategoryID)
count = "SELECT COUNT(*) as Total FROM Items WHERE TopicID=CategoryID"
Set rs = connect.Execute(count)
CountAds = rs.Fields("Total")
rs.Close
Set rs = Nothing
End Function

I receive the error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e10'

[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 2.

/campbemr/subroutines.asp, line 48

I removed the WHERE TopicID = CategoryID
and the error went away. So that tells me that I am not passing the variable into the SQL statement correctly. How is that done?
 


Campbemr,

count = "SELECT COUNT(*) as Total FROM Items WHERE TopicID=CategoryID"

SHOULD BE:

count = "SELECT COUNT(*) as Total FROM Items WHERE TopicID='" & CategoryID & "'"

Cheers,
fengshui1998

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top