如何给SQL SERVER存储过程传递数组参数

2025-02-28 03:12:17
推荐回答(1个)
回答1:

但可用其它的方法来实现。 1. You could simulate an array by passing one or more varchar(255) fields with comma-separated values and then use a WHILE loop with PATINDEX and SUBSTR to extract the values. 1、你可以使用几个VARCHAR(255)字段来模拟数组,字段中用逗号分开各个数据,然后使用循环和PATINDEX和SUBSTR分开这些数据。 2. The more usual way to do this would be to populate a temporary table with the values you need and then use the contents of that table from within the stored-procedure. Example of this below 2、通常这种方法需要为这些数据创建一个临时表,然后在存储过程使用表中的内容。如下例 create procedure mytest @MyParmTempTable varchar(30)asbegin-- @MyParmTempTable contains my parameter list... 这个变量是包含参数的表名 create table #MyInternalList ( list_item varchar( 2 ) not null) set nocount on insert #MyInternalList exec ( "select * from " + @MyParmTempTable ) set nocount off select *from sysobjects