Passing array as Parameter to SQL 2005 stored procedure

后端 未结 4 1574
时光取名叫无心
时光取名叫无心 2021-01-15 10:11

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 a

4条回答
  •  猫巷女王i
    2021-01-15 10:43

    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('' + REPLACE(@data, @delimiter, '') + '' AS XML)
    SELECT  T.split.value('.', 'nvarchar(max)') AS data
    FROM    @textXML.nodes('/d') T(split)
    

提交回复
热议问题