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

Using "in" clause with parameterized queries

Status
Not open for further replies.

M3Fan

Programmer
Dec 28, 2001
73
US
Is there any way, using the command object with parameters, to pass in a comma-delimited list of numbers (a string) into an "IN" clause? Such as below:

dim tempcmd 'as ado command
dim parm1 'as command parameter
dim parm2 'as command parameter
Set tempcmd = CreateObject("ADODB.Command")
tempcmd.ActiveConnection = db
tempcmd.CommandText = "Delete from MyTable where " & _
"MyID in (?) and userID=?"
tempcmd.CommandType = adCmdText

Set parm1 = tempcmd.CreateParameter("myIDList",adVarChar,1)

Set parm2 = tempcmd.CreateParameter("userID",adInteger,1)
parm1.Value = MyUserID
parm2.Value = MyCommaDelimitedList
tempcmd.Parameters.Append parm1
tempcmd.Parameters.Append parm2
tempcmd.Execute

Let's say
MyCommaDelimitedList = "1,2,3,4,5"
 
The point of using the parameter is to not concatenate the string. The idea is to let the command object use the parameter in place of the ? to protect from sql injection, etc... Thanks though.
 
I can't conclusively say it isn't possible to do this with the command object. Although I know you can do it in .NET. In this case, you may just be better off creating a stored procedure. It'll only take a minute if it's just a simple query anyway...

All hail the INTERWEB!
 
That's the direction I was leaning towards- I'm pretty sure it is impossible to do...
 
Good deal. Well, let us know if I find out a way to do this - I'd be curious.

All hail the INTERWEB!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top