需要在sql server里用到数组这样的数据结构.而transact-sql没有内建数组,听说可以用字符串配合临时表来实现,自己试了,解决方法如下 :
create proc [dbo].[CreateArray]
@string varchar(1024)
as
create table #array (id int identity,value varchar(32))
set @string='insert #array select '''+replace(@string,',','''as str union all select ''')+''''
exec(@string)
select * from #array
go
@string varchar(1024)
as
create table #array (id int identity,value varchar(32))
set @string='insert #array select '''+replace(@string,',','''as str union all select ''')+''''
exec(@string)
select * from #array
go
执行如下 :
exec CreateArray 'CChess,Dig,GoBang,LandLord,Majiang'