Click here to Skip to main content
15,905,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello every one,

Please I need to send many values in a array-parameter (varchar, integer) of stored procedure,
because i do not want to make many inserts, this is the principal reason.

Pleae tell me if it is posible???

How???

Thanks in advance.

Leo
Posted
Updated 18-May-11 5:11am
v2

1 solution

Google[^] is your friend :)
Most of those solutions involve comma seperated values but 1 has XML solution such as

SQL
CREATE PROC dbo.GetOrderList4
(
    @OrderList varchar(1000)
)
AS
BEGIN
    SET NOCOUNT ON
    DECLARE @DocHandle int
    EXEC sp_xml_preparedocument @DocHandle OUTPUT, @OrderList
    SELECT o.OrderID, CustomerID, EmployeeID, OrderDate
    FROM    dbo.Orders AS o
        JOIN
        OPENXML (@DocHandle, '/ROOT/Ord',1) WITH (OrderID  int) AS x
        ON o.OrderID = x.OrderID
    EXEC sp_xml_removedocument @DocHandle
END
GO
GRANT EXEC ON dbo.GetOrderList4 TO WebUser
GO

SQL
--Call this stored procedure as shown below, and it will retrieve OrderID, CustomerID, EmployeeID and OrderDate columns for the given order numbers:
EXEC dbo.GetOrderList4 '
<ROOT>
<Ord OrderID = "10248"/> <Ord OrderID = "10252"/>
<Ord OrderID = "10256"/> <Ord OrderID = "10261"/>
<Ord OrderID = "10262"/> <Ord OrderID = "10263"/>
<Ord OrderID = "10264"/> <Ord OrderID = "10265"/>
<Ord OrderID = "10300"/> <Ord OrderID = "10311"/>
<Ord OrderID = "11068"/> <Ord OrderID = "11069"/>
<Ord OrderID = "11070"/> <Ord OrderID = "11071"/>
<Ord OrderID = "11072"/> <Ord OrderID = "11073"/>
<Ord OrderID = "11074"/> <Ord OrderID = "11075"/>
<Ord OrderID = "11076"/> <Ord OrderID = "11077"/>
</ROOT>'
GO


 
Share this answer
 
v2
Comments
leocode7 18-May-11 11:50am    
sounds very good.
i will to test your code,
please wait my news...
:)

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