Since there is no Sqlserver array parameter, what's the best way to proceed?

前端 未结 5 1181
孤独总比滥情好
孤独总比滥情好 2020-12-10 19:23

I need to create multiple records in sqlserver, each with the same value in column A, but with a unique value in column B. I have the values for column B in an array.

<
5条回答
  •  天命终不由人
    2020-12-10 19:59

    The easiest way to implement this is using Option 1: passing the array as a delimited string. I used to do this in the pre-sql2005 days in conjunction with this TSQL Split Function. I would pass the array using "|" as a delimiter.

    These days, I serialize the array into XML and then insert the contents into a table variable for processing using the sp_xml_preparedocument stored procedure.

    I wouldn't use option 2 since it makes multiple calls to database.

提交回复
热议问题