CREATE PROCEDURE WANGLONG_INSERT ( @msgcontent varchar(140) ,@mobile varchar(20),@epid varchar(20))
AS
begin
insert into DYHIKEMESSAGES (TO_MOBILE, MSG_CONTENT, EPID) select @mobile, @msgcontent, @epid
end
GO
-----------------
CREATE PROCEDURE WANGLONG_MT ( @msgcontent varchar(1000) ,@MOBILE VARCHAR(20), @EPID VARCHAR(20))
AS
declare @content varchar(1000)
declare @str1 varchar(140) ,@str2 varchar(140),@str3 varchar(140)
declare @str4 varchar(140) ,@str5 varchar(140),@str6 varchar(140)
declare @str7 varchar(140) ,@str8 varchar(140),@str9 varchar(140),@str10 varchar(140)
declare @len int
declare @idx int
declare @maxlen int
--declare @epid varchar(20)
select @content= @msgcontent
select @len = len(@content)
select @idx = 1
select @maxlen = 59
if @len <=64
return
while @len > @maxlen
begin
if @idx =1
select @str1 = substring(@content,1,@maxlen)
else if @idx =2
select @str2 = substring(@content,1,@maxlen)
else if @idx =3
select @str3 = substring(@content,1,@maxlen)
else if @idx =4
select @str4 = substring(@content,1,@maxlen)
else if @idx =5
select @str5 = substring(@content,1,@maxlen)
else if @idx =6
select @str6 = substring(@content,1,@maxlen)
else if @idx =7
select @str7 = substring(@content,1,@maxlen)
else if @idx =8
select @str8 = substring(@content,1,@maxlen)
else if @idx =9
select @str9 = substring(@content,1,@maxlen)
select @content=substring(@content,@maxlen+1,@len-@maxlen)
select @len=len(@content)
select @idx = @idx+1
end
if @str8 is not null
begin
select @str1='(1/9)'+@str1; select @str2='(2/9)'+@str2; select @str3='(3/9)'+@str3; select @str4='(4/9)'+@str4;
select @str5='(5/9)'+@str5; select @str6='(6/9)'+@str6; select @str7='(7/9)'+@str7; select @str8='(8/9)'+@str8;
select @str9='(9/9)'+@content;
execute WANGLONG_INSERT @str1,@MOBILE,@EPID
execute WANGLONG_INSERT @str2,@MOBILE,@EPID
execute WANGLONG_INSERT @str3,@MOBILE,@EPID
execute WANGLONG_INSERT @str4,@MOBILE,@EPID
execute WANGLONG_INSERT @str5,@MOBILE,@EPID
execute WANGLONG_INSERT @str6,@MOBILE,@EPID
execute WANGLONG_INSERT @str7,@MOBILE,@EPID
execute WANGLONG_INSERT @str8,@MOBILE,@EPID
execute WANGLONG_INSERT @str9,@MOBILE,@EPID
end
else if @str7 is not null
begin
select @str1='(1/8)'+@str1; select @str2='(2/8)'+@str2; select @str3='(3/8)'+@str3; select @str4='(4/8)'+@str4;
select @str5='(5/8)'+@str5; select @str6='(6/8)'+@str6; select @str7='(7/8)'+@str7; select @str8='(8/8)'+@content;
execute WANGLONG_INSERT @str1,@MOBILE,@EPID
execute WANGLONG_INSERT @str2,@MOBILE,@EPID
execute WANGLONG_INSERT @str3,@MOBILE,@EPID
execute WANGLONG_INSERT @str4,@MOBILE,@EPID
execute WANGLONG_INSERT @str5,@MOBILE,@EPID
execute WANGLONG_INSERT @str6,@MOBILE,@EPID
execute WANGLONG_INSERT @str7,@MOBILE,@EPID
execute WANGLONG_INSERT @str8,@MOBILE,@EPID
end
else if @str6 is not null
begin
select @str1='(1/7)'+@str1; select @str2='(2/7)'+@str2; select @str3='(3/7)'+@str3; select @str4='(4/7)'+@str4;
select @str5='(5/7)'+@str5; select @str6='(6/7)'+@str6; select @str7='(7/7)'+@content
execute WANGLONG_INSERT @str1,@MOBILE,@EPID
execute WANGLONG_INSERT @str2,@MOBILE,@EPID
execute WANGLONG_INSERT @str3,@MOBILE,@EPID
execute WANGLONG_INSERT @str4,@MOBILE,@EPID
execute WANGLONG_INSERT @str5,@MOBILE,@EPID
execute WANGLONG_INSERT @str6,@MOBILE,@EPID
execute WANGLONG_INSERT @str7,@MOBILE,@EPID
end
else if @str5 is not null
begin
select @str1='(1/6)'+@str1; select @str2='(2/6)'+@str2; select @str3='(3/6)'+@str3; select @str4='(4/6)'+@str4;
select @str5='(5/6)'+@str5; select @str6='(6/6)'+@content;
execute WANGLONG_INSERT @str1,@MOBILE,@EPID
execute WANGLONG_INSERT @str2,@MOBILE,@EPID
execute WANGLONG_INSERT @str3,@MOBILE,@EPID
execute WANGLONG_INSERT @str4,@MOBILE,@EPID
execute WANGLONG_INSERT @str5,@MOBILE,@EPID
execute WANGLONG_INSERT @str6,@MOBILE,@EPID
end
else if @str4 is not null
begin
select @str1='(1/5)'+@str1; select @str2='(2/5)'+@str2; select @str3='(3/5)'+@str3; select @str4='(4/5)'+@str4;
select @str5='(5/5)'+@content;
execute WANGLONG_INSERT @str1,@MOBILE,@EPID
execute WANGLONG_INSERT @str2,@MOBILE,@EPID
execute WANGLONG_INSERT @str3,@MOBILE,@EPID
execute WANGLONG_INSERT @str4,@MOBILE,@EPID
execute WANGLONG_INSERT @str5,@MOBILE,@EPID
end
else if @str3 is not null
begin
select @str1='(1/4)'+@str1; select @str2='(2/4)'+@str2; select @str3='(3/4)'+@str3; select @str4='(4/4)'+@content;
execute WANGLONG_INSERT @str1,@MOBILE,@EPID
execute WANGLONG_INSERT @str2,@MOBILE,@EPID
execute WANGLONG_INSERT @str3,@MOBILE,@EPID
execute WANGLONG_INSERT @str4,@MOBILE,@EPID
end
else if @str2 is not null
begin
select @str1='(1/3)'+@str1; select @str2='(2/3)'+@str2; select @str3='(3/3)'+@content;
execute WANGLONG_INSERT @str1,@MOBILE,@EPID
execute WANGLONG_INSERT @str2,@MOBILE,@EPID
execute WANGLONG_INSERT @str3,@MOBILE,@EPID
end
else if @str1 is not null
begin
select @str1='(1/2)'+@str1; select @str2='(2/2)'+@content;
execute WANGLONG_INSERT @str1,@MOBILE,@EPID
execute WANGLONG_INSERT @str2,@MOBILE,@EPID
end
GO
----------------------------------------------
CREATE TRIGGER [WANGLONG_TRIG] ON dbo.DYHIKEMESSAGES
FOR INSERT
AS
BEGIN TRANSACTION
declare @len int
declare @mobile varchar(20)
declare @content varchar(1000)
declare @idx int
declare @icount int
declare @epid varchar(20)
select @icount = count(*) from INSERTED
--select @icount = @@ROWCOUNT
select top 1 @idx=dymsgid from INSERTED
while @icount>0
begin
select top 1 @len=len(msg_content),@content=msg_content,@mobile=to_mobile, @epid = epid from INSERTED where dymsgid =@idx
if SUBSTRING(@mobile,1,1)='0' and @len> 52
begin
UPDATE DYHIKEMESSAGES SET SEND_OUT_FLAG=8 WHERE DYMSGID=@idx
execute WANGLONG_XL_MT @content, @mobile,@epid
end
select @idx=@idx+1
select @icount=@icount -1
if SUBSTRING(@mobile,1,1)='1' and @len> 64
begin
--DELETE FROM DYHIKEMESSAGES WHERE DYMSGID=@idx
UPDATE DYHIKEMESSAGES SET SEND_OUT_FLAG=8 WHERE DYMSGID=@idx
execute WANGLONG_MT @content, @mobile,@epid
end
select @idx=@idx+1
select @icount=@icount -1
end
COMMIT TRANSACTION