Re: Parameterized queries with where clause including 'in'



Mike.Surel@xxxxxxxx wrote on 29 Nov 2005 14:42:22 -0800:

> I've searched for a while now to see an example of using a
> parameterized query using the 'in' keyword in a SELECT query and can't
> find anything that works. I'm working with VBScript in an ASP page.
>
> If I have a recordset opened with a query like this:
> inClause = "'user1','user2','user3'"
> "SELECT * FROM myTable where USERID IN (" + inClause + ")"
>
> it works fine. However if I use an adodb command object because I would
> like to use parameterized queries and I do the following
>
> sqlStr = "SELECT * FROM myTable where USERID IN (?)"
> cmd.CommandText=sqlStr
>
> set param1=cmd.CreateParameter("USERID",200,1,255,inClause)
> cmd.Parameters.Append param1
> set rs = cmd.Execute
>
> the recordset always comes back with BOF and EOF true. No records are
> returned. Anybody out there have a clue what I'm doing wrong? I've been
> banging my head against this for a while. Any help would be greatly
> appreciated.


What's happening is that SQL Server is attempting to find a row that has a
USERID that matches the entire string, ie.

SELECT * FROM myTable where USERID IN ('''user1'',''user2'',''user3''')


Check out http://vyaskn.tripod.com/passing_arrays_to_stored_procedures.htm
for some examples of how you can achieve what you're trying to do.

Dan


.



Relevant Pages

  • quick SELECT query question
    ... say I have an Access database called tests containing the following fields: ... userid, test_date, test_type. ... criteria I want and hit a button to run a SELECT query against my database. ... tests matching the selected criteria and put into a RecordSet fine, ...
    (microsoft.public.inetserver.iis.activeserverpages)
  • SQL SELECT statement
    ... say I have a simple Access database called tests containing the following ... userid, test_date, test_type. ... criteria I want and hit a button to run a SELECT query against my database. ... tests matching the selected criteria and put into a RecordSet fine, ...
    (microsoft.public.access.adp.sqlserver)
  • SELECT queries
    ... say I have a simple Access database called tests containing the following ... userid, test_date, test_type. ... criteria I want and hit a button to run a SELECT query against my database. ... tests matching the selected criteria and put into a RecordSet fine, ...
    (microsoft.public.access.queries)
  • Parameterized queries with where clause including in
    ... parameterized query using the 'in' keyword in a SELECT query and can't ... the recordset always comes back with BOF and EOF true. ...
    (microsoft.public.data.ado)
  • Re: Help with Microsoft help on linking Access to Outlook
    ... Tools - references - tick Microsoft Outlook object library. ... in the criteria cell in the graphical query builder. ... the same filtered recordset every time. ... normal form to allow the normal filtering process and viewing of the ...
    (microsoft.public.access.formscoding)