USE [EtownDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create PROCEDURE InsWxqunfaChildtb
@logid int,
@sql text --需要分割的字符串
AS
set @sql = replace(@sql,' ','')
DECLARE @Run bit --继续循环的标志
declare @dotIndex as int
declare @tablename as varchar(100)
set @Run = 1
begin
set nocount on
set xact_abort on
begin try
begin tran
while(@Run = 1)
BEGIN
if(len(@sql)>0)--如果表名集合还不为空,则进行一下操作
begin
set @dotIndex=CharIndex(',',@sql)
if(@dotIndex = 0)--如果没有找到',' 证明 @sql
begin
set @tablename = @sql
set @Run=0
end;
else
begin
set @tablename = substring(@sql,1,@dotIndex-1) --表名
set @sql=substring(@sql,@dotIndex+1,len(@sql)) --把存储表名的串的长度缩短至后一个
end;
insert into wxqunfa_wxno(weixin,logid) values(@tablename,@logid)
end;
END
commit tran
return 1;
end try
begin catch
if xact_state()=-1
rollback tran;
return 0;
end catch
end