2

How to pass array as parameter to a Store Procedure in SQL Server 2005, i this is not possible SQL server 2000, so we pass comma separated values in past.

any help appreciated

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Faizan Dosani
  • 81
  • 2
  • 3
  • 8

4 Answers4

2

For a number of different ways to do this, please see:

Arrays and Lists in SQL Server 2005

Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • Thanks for your response, seems like we are unable to pass array directly but can achieve desired goal through many alternatives mention in above link – Faizan Dosani Dec 17 '09 at 15:09
0

This is still the case with Sql Server 2005.

You make use of the XML type

XML Support in Microsoft SQL Server 2005

Here is an example of how to split a string into rows using the XML data type

DECLARE @textXML XML
DECLARE @data NVARCHAR(MAX), 
        @delimiter NVARCHAR(5)

SELECT  @data = 'A,B,C',
        @delimiter = ','

SELECT    @textXML = CAST('<d>' + REPLACE(@data, @delimiter, '</d><d>') + '</d>' AS XML)
SELECT  T.split.value('.', 'nvarchar(max)') AS data
FROM    @textXML.nodes('/d') T(split)
Adriaan Stander
  • 162,879
  • 31
  • 289
  • 284
0

Instead of a CSV, you could send an XML and then parse it in the procedure. For an example, look at Passing lists to SQL Server 2005 with XML Parameters

Vedran
  • 757
  • 6
  • 21
0

See Passing an array or DataTable into a stored procedure for a method of passing arrays as image / varbinary objects and parsing them in the SP which is possible in SQL 2000 as well.

doza
  • 1,521
  • 11
  • 14