Declare @cityProId int
select @cityProId=id from Provinces where ProvincesName=@ProvincesName
print @cityProId
insert into cities(ProId,cityName) select @cityProId as proid,col as cityname from dbo.f_split(@chars,@c)
END
GO

alter function fn_split3(
@strs varchar(max),@c varchar(2)
)
returns @tmp table(colu varchar)
as
begin 
	if(IsNULL(@strs,'')<>'')
	begin 
	set @strs=@strs+','
		while(charindex(@c,@strs)<>0)
		begin
			insert into @tmp(colu) values(substring(@strs,1,charindex(@c,@strs)-1))
			set @strs=substring(@strs,charindex(@c,@strs)+1,len(@strs))
			--set @strs=stuff(@strs,1,charindex(@c,@strs),'')
		 end
		
	end
	return
end 

go

select * from dbo.fn_split3('1,2,3,4,5',',')

 posted on 2011-02-18 15:08  纳兰_容若  阅读(123)  评论(0编辑  收藏  举报