Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I want to no how to pass array type parameter from a procedure's parameter and how i will compare that parameter array value with an existing cursor value in a same procedure body.

example:

i want to pass a{1,2,3,4,5} varchar type in that procedure. and it will compare with the existing cursor value c_abc {1,2,4,9}.
Posted
Updated 14-Jan-16 0:51am
Comments
ZurdoDev 14-Jan-16 7:36am    
SQL does not support array types as parameters, at least not when I last checked.

As mentioned in above answer you need to use Microsoft SQL Server 2008 or higher.

Then you can use table-valued parameters to pass the multiple data values through a single parameter.

Here is an example.

Step 1: you need to create the table-valued parameter type as you need.

SQL
CREATE TYPE dbo.Products AS TABLE
    ( ID int, Description varchar(50) )


Step 2: Then create a Stored Prcedure
SQL
CREATE PROCEDURE getProductDetails 
    (@itemIDs dbo.Products)
AS
BEGIN

SELECT * FROM @Products

END


Step 3: In order to pass the data from c# or what ever the code, create a DataTable object and pass it to the Stored Procedure as we pass to the normal parameters.
 
Share this answer
 
Comments
Bittu14 20-Jan-16 3:40am    
Thanks a lot.
Assuming you're using Microsoft SQL Server 2008 or higher, use table-valued parameters:
Table-Valued Parameters[^]
Table-Valued Parameters (Database Engine)[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900