if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Getepnum] and Xtype in (n ' FN ', n ' IF ', n ' TF '))
Drop function [dbo]. [Getepnum]
Go
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Getstrcount] and Xtype in (n ' FN ', n ' IF ', n ' TF '))
Drop function [dbo]. [Getstrcount]
Go
if exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ Getstrofindex] and Xtype in (n ' FN ', n ' IF ', n ' TF '))
Drop function [dbo]. [Getstrofindex]
Go
SET QUOTED_IDENTIFIER ON
Go
SET ANSI_NULLS on
Go
---This function calls the other two functions directly, and you can read the two functions mentioned below first.
CREATE function Getepnum (@str varchar (8000))
Returns varchar (8000)
As
Begin
DECLARE @str_return varchar (8000)
DECLARE @i int
DECLARE @temp_i int
DECLARE @onlineornot int
DECLARE @findepnumok int
--To get a epnum,
--Rules: first from the Chatid, if there is online, then get the front must be returned online
--If all is not on the line, return ' 00000000 '
Select @findepnumok = 0
Select @temp_i = 0
IF Len (@str) <=0
Begin
SELECT @str_return = ' 00000000 '
End
Else
Begin
Select @i = Dbo.getstrcount (@str, ', ')
While @temp_i <@i
BEGIN
Select @onlineornot = online from Wwchat_user where Epnum=dbo.getstrofindex (@str, ', ', @temp_i)
IF (@onlineornot =1)
Begin
Select @str_return =dbo.getstrofindex (@str, ', ', @temp_i)
Select @findepnumok = 1--Find epnum after 1
Break
End
ELSE
Begin
Select @temp_i = @temp_i + 1
Select @findepnumok = 0--Epnum 1 not found
End
End
If @findepnumok = 0
Begin
SELECT @str_return = ' 00000000 '
End
End
Return @str_return
End
Go
SET QUOTED_IDENTIFIER OFF
Go
SET ANSI_NULLS on
Go
SET QUOTED_IDENTIFIER ON
Go
SET ANSI_NULLS on
Go