sql数组插入
alter proc insertup
(@unam nchar(20),@ups nchar(30))
as
begin
insert into usertb(uname) values(@unam)
declare @dou int
declare @coudou int
declare @str int
declare @id int
set @id=@@identity
set @coudou=1
print @coudou
while(charindex(',',@ups,@coudou)>0)
begin
set @dou=charindex(',',@ups,@coudou)
print @id
set @str=cast(substring(@ups,@dou-1,1) as int)
print @str
insert into up(uid,pid) values(@id, @str )
set @coudou=@dou+1
end
if(charindex(',',@ups,@coudou)=0)
begin
set @str=cast(substring(@ups,len(@ups),1) as int)
print @str
insert into up(uid,pid) values(@id, @str )
end
end
说白了也就是charindex和substring函数的使用。这只是一种方法,在代码里写就更简单了

“一步登天做不到,但一步一个脚印能做到。一鸣惊人不好做,但一股劲做好一件事,可以做。一下成为天才不可能,但每天进步一点点有可能”
浙公网安备 33010602011771号