Possible Duplicate:
T-SQL stored procedure that accepts multiple Id values可能重复:接受多个Id值的T-SQL存储过程
Does T-SQL accomodate for array values as parameters for stored procedures? If so how can this be achieved.
T-SQL是否适合将数组值作为存储过程的参数?如果是这样,怎么能实现。
4 个解决方案
#1
T-SQL dialect in SQL Server 2005 does not support neither arrays, nor anything similar, so they have to be emulated. SQL Server 2008, however, supports table-valued parameters, which can be used as arrays.
SQL Server 2005中的T-SQL方言既不支持数组也不支持任何类似,因此必须模拟它们。但是,SQL Server 2008支持表值参数,可用作数组。
#2
What I prefer to use instead is a comma (or other special character) separated list which I will split/explode first thing in my sproc. This will then give me a table of values to work with and that I can then join on or perform other actions on later on in my stored procedures.
我更喜欢使用的是逗号(或其他特殊字符)分隔列表,我将在我的sproc中拆分/爆炸。然后,这将为我提供一个可以使用的值表,然后我可以在以后的存储过程中加入或执行其他操作。
You can also look into passing in table parameters, but I kind of like my way more just as a personal preference.
您还可以查看传递表格参数,但我更喜欢我的方式,更像是个人偏好。
#3
It was often achieved passing in a CSV, which is obviously limited. With SQL 2005 an Xml parameter may be much better suited, with a serializer suited to your needs perhaps.
它经常通过CSV传递,这显然是有限的。使用SQL 2005,Xml参数可能更适合,可能还有适合您需求的序列化程序。
There may be more and I'll come back if I think of any.
可能会有更多,如果我想到的话,我会回来。
#4
There are no arrays in sqlserver. However, What are you trying to do? What would the values as parameters be used for? You can send sql an "array" but the sp would have to be dynamic.
sqlserver中没有数组。但是,你想做什么?作为参数的值会用于什么?你可以发送一个“数组”的SQL,但sp必须是动态的。
#1
T-SQL dialect in SQL Server 2005 does not support neither arrays, nor anything similar, so they have to be emulated. SQL Server 2008, however, supports table-valued parameters, which can be used as arrays.
SQL Server 2005中的T-SQL方言既不支持数组也不支持任何类似,因此必须模拟它们。但是,SQL Server 2008支持表值参数,可用作数组。
#2
What I prefer to use instead is a comma (or other special character) separated list which I will split/explode first thing in my sproc. This will then give me a table of values to work with and that I can then join on or perform other actions on later on in my stored procedures.
我更喜欢使用的是逗号(或其他特殊字符)分隔列表,我将在我的sproc中拆分/爆炸。然后,这将为我提供一个可以使用的值表,然后我可以在以后的存储过程中加入或执行其他操作。
You can also look into passing in table parameters, but I kind of like my way more just as a personal preference.
您还可以查看传递表格参数,但我更喜欢我的方式,更像是个人偏好。
#3
It was often achieved passing in a CSV, which is obviously limited. With SQL 2005 an Xml parameter may be much better suited, with a serializer suited to your needs perhaps.
它经常通过CSV传递,这显然是有限的。使用SQL 2005,Xml参数可能更适合,可能还有适合您需求的序列化程序。
There may be more and I'll come back if I think of any.
可能会有更多,如果我想到的话,我会回来。
#4
There are no arrays in sqlserver. However, What are you trying to do? What would the values as parameters be used for? You can send sql an "array" but the sp would have to be dynamic.
sqlserver中没有数组。但是,你想做什么?作为参数的值会用于什么?你可以发送一个“数组”的SQL,但sp必须是动态的。