declare @email\_source varchar(MAX); --1.原始发件人字段
declare @key\_name varchar(50); --2.我方卷号或客户代码
declare c\_cur cursor for select distinct vc\_your\_email,vc\_our\_ref\_or\_code from #ip\_special\_email\_total where vc\_your\_email like '%@%' order by vc\_our\_ref\_or\_code;
open c\_cur;
fetch next from c\_cur into @email\_source,@key\_name;
while (@@FETCH\_STATUS = 0)
begin
declare @split\_str varchar(50) --分隔符
declare @pos int --当前位置
declare @split\_len int --分隔符长度
declare @split\_index int --最近的分隔符位置
declare @split\_last\_index int --上次分隔符位置
declare @avc\_email varchar(500)
set @split\_str = ';' --指定分隔符
set @pos = 1
set @split\_len = len(@split\_str)
set @split\_index = 0
set @split\_last\_index = 0
while (@pos <= len(@email\_source))
begin
if @split\_index > 0 set @split\_last\_index = @split\_index
set @split\_index = charindex(@split\_str, @email\_source, @pos)
set @pos = @pos + @split\_len
if @pos = len(@email\_source) set @split\_index = @pos + @split\_len
if @split\_index > @split\_last\_index
begin
set @avc\_email = substring(@email\_source,(@split\_last\_index + @split\_len),(@split\_index - @split\_last\_index - @split\_len))
if isnull(@avc\_email,'')<>'' insert #ip\_single\_email\_total select @avc\_email,@key\_name
end
end
fetch next from c\_cur into @email\_source,@key\_name;
end
close c\_cur
deallocate c\_cur
手机扫一扫
移动阅读更方便
你可能感兴趣的文章