Re: Passing comma seperated values to a stored proc

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Keith Kratochvil (sqlguy.back2u_at_comcast.net)
Date: 12/22/04


Date: Wed, 22 Dec 2004 10:41:05 -0600

Here is an excellent article:
http://www.sommarskog.se/dynamic_sql.html#List

-- 
Keith
"M Smith" <msmith@avma.org> wrote in message
news:OIWACTE6EHA.2592@TK2MSFTNGP09.phx.gbl...
> I have an application where the user will type in ID numbers into a single
> field in an ASP page.  They can type in multiple IDs if they are seperated
> by a comma.  I want to pass this string into a Stored Proc and just use an
> "in" command in the where clause to return a recordset back to the ASP
page.
> The problem is that the ID numbers are integer and the parameter is a
> varchar.  When I try to pass multiple IDs into the Stored Proc I get an
> error.
> Here is the Stored Proc
> CREATE PROCEDURE test @pvID as varchar(500) AS
>         Select * from member_t where member_ID in (@pvID)
> GO
> When I try it by typing  - exec test '123456,123457,123458'  -  I get this
> error
> "Syntax error converting the varchar value '123456,123457,123458' to a
> column of data type int."
>
> How would I go about converting the string to an integer and still use the
> In statement.
> Thanks
>
>
>
>


Relevant Pages

  • Re: SqlException after Adapter.Update: how to determine the source column and parameter involved?
    ... the error does indicate that an integer column is being assigned the string 'Test': ... I've stepped through every parameter in the InsertCommand.Parameter collection, and looked at their values in the debugger, and the only parameter that has 'Test' for its value is a varchar parameter size=40 tied to a varcharparameter in the stored proc which updates a varcharcolumn in the underlying table. ... I would really like to know What integer column has been mapped to a varchar parameter. ... {"Syntax error converting the varchar value 'Test' to a column of data type int."} ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Want to put calculation into a string
    ... 'Program Requirement' = ... > castas real) as varchar)> else ... > Syntax error converting the varchar value '50910.3' to a column of data> type int. ... > Any ideas as to how to string this calculation into what I think should> be a varchar field? ...
    (microsoft.public.sqlserver.programming)
  • error while i return a varchar from a Stored Proc
    ... I want to return a string (varchar) fro am SP. ... create proc hellotest @ret varcharoutput as ... Syntax error converting the varchar value 'hello' to a column of data type ... So cant we return a string from a SP? ...
    (microsoft.public.sqlserver.programming)
  • PL/I coded DB2 Stored Procedure
    ... I have a PL/I Stored Proc that is doing a DB2 Update of a VARCHAR ...
    (comp.lang.pl1)
  • RE: executing sproc
    ... Issue is resolved by adding Initialization string to DSN. ... for the stored proc but not for the SQL statement. ... > establish a new Connection Cnct and open it successfully. ...
    (microsoft.public.data.ado)