下面是一个sq serverl的存储过程其中一部分实现了类似split的功能,我没有把这部分单独拿出来。(有更好的方法希望能与我联系:vince6799@hotmail.com或访问www.miplat.com)
CREATE PROCEDURE savesend(@mobile as nvarchar(4000),@content as nvarchar(70),@sendtime as nvarchar(50),@sender as nvarchar(50)) AS
declare @stime nvarchar(50),@smobile nvarchar(50)
declare @icount int,@pos int,@len int
set @len=len(@mobile)
set @icount=1
if (@sendtime<>'' )
begin
set @stime=substring(@sendtime,1,4)+'-'+substring(@sendtime,5,2)+'-'+substring(@sendtime,7,2)+' '+substring(@sendtime,9,2)+':'+substring(@sendtime,11,2)+':'+substring(@sendtime,13,2)
while(@icount<@len)
begin
set @pos=charindex(',',@mobile,@icount)
if(@pos<=0)
begin
set @smobile=substring(@mobile,@icount,@len-@icount+1)
insert into sms_out(sms_send_mobile,sms_send_content,sms_send_time,sms_send_user) values(@smobile,@content,cast(@stime as nvarchar(50)),@sender)
break
end
set @smobile=substring(@mobile,@icount,@pos-@icount)
insert into sms_out(sms_send_mobile,sms_send_content,sms_send_time,sms_send_user) values(@smobile,@content,cast(@stime as nvarchar(50)),@sender)
set @icount=@pos+1
end
end
else
begin
while(@icount<@len)
begin
set @pos=charindex(',',@mobile,@icount)
if(@pos<=0)
begin
set @smobile=substring(@mobile,@icount,@len-@icount+1)
insert into sms_out(sms_send_mobile,sms_send_content,sms_send_user) values(@smobile,@content,@sender)
break
end
set @smobile=substring(@mobile,@icount,@pos-@icount)
insert into sms_out(sms_send_mobile,sms_send_content,sms_send_user) values(@smobile,@content,@sender)
set @icount=@pos+1
end
end
GO