How to pass a variable number of parameters to a SQL Server stored procedure?

前端 未结 4 1137
执笔经年
执笔经年 2021-02-05 16:32

I used SQL Server 2005 for my small web application. I Want pass parameters to SP . But there is one condition. number of parameter that can be change time to time. Think ,this

4条回答
  •  说谎
    说谎 (楼主)
    2021-02-05 16:54

    Preparing and exctracting tags from XML is aperformance killer. The inconsistant execution timings depends on whether plan is cached or not.

    Using NVARCHAR(MAX) instead is a better option. Just prepare you parameter strings with "@name=Value" pair, and add a unique parameter sepearetor if needed. Inside the procedure use SUBSTRING, CHARINDEX, etc. to get individual parameters.

提交回复
热议问题