I am trying to make a query which will search for the ID's 5, 6 and 23(Those are just random numbers and could potentially be more). Rather than making a loop in my code to query each separate ID I was wondering if it was possible to query them all at once and return each row for the individual IDs.

Recommended Answers

All 2 Replies

Hello,

All you have to do is select from a list like this:

Select * from table1
where ID in (5, 6, 23)

I have the same question somewhat... except I need the query string to populate the values for the IN statement this is the code I have but it's not working and I'm stuck and am in DIRE need of an answer:
<%
Dim rsAuto__print
For i=1 to (Trim(UCase(Request.QueryString("print"))).Count
If (Trim(UCase(Request.QueryString("print"))) (i) = Trim(UCase(rsAuto.Fields.Item("vin").Value)) Then
rsAuto__print = Trim(UCase(Request.QueryString("print"))
End If
Next
%>
<%
Dim rsAuto
Dim rsAuto_cmd
Dim rsAuto_numRows

Set rsAuto_cmd = Server.CreateObject ("ADODB.Command")
rsAuto_cmd.ActiveConnection = MM_Regal_STRING
rsAuto_cmd.CommandText = "SELECT * FROM AUTODETA as t1 LEFT JOIN MAKES AS t2 ON t1.makesx = t2.makesx WHERE vin IN ("& rsAuto__print &")"
rsAuto_cmd.Prepared = true
rsAuto_cmd.Parameters.Append rsAuto_cmd.CreateParameter("param1", 200, 1, 255, rsAuto__print) ' adVarChar

Set rsAuto = rsAuto_cmd.Execute
rsAuto_numRows = 0
%>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.