-------------------------------------------------- -------------- / ** * Copyright: Shutouxiang [E.ALPHA] All; * * EMAIL: Ealpha (AT) MSN (Dot) COM; * MSN: Ealpha (AT) MSN (Dot) Com; * QQ: 9690501 * * All reproduced please indicate this information! * / ------------------------------------------------ ---------------- 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 goset Ansi_nulls on Go --- This function calls another two function, you can read the below mentioned two functions CREATE function getEPnum (@str varchar (8000)) returns varchar (8000) asbegin declare @str_return varchar (8000) declare @i int declare @temp_i int declare @onlineornot int declare @ FINDEPNUMOK INT - Used to get an epnum, - rule: Before you get from Chatid, if there is online, get the most in front to return - if all is not online, return '00000000' select @findepnumok = 0 Select @temp_i = 0 if len (@STR) <= 0 b EGIN 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 - After finding EPNUM is set to 1 BREAK end ELSE begin select @temp_i = @temp_i 1 select @findepnumok = 0 - epnum set not found after 1 end END if @findepnumok = 0 begin SELECT @str_return = '00000000' end end return @str_return end GOSET QUOTED_IDENTIFIER OFF GOSET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GOSET ANSI_NULLS ON GO - getstrcount without dividing the input string, and the delimiter - return the number of CREATE function getstrcount (@str varchar (8000), @ splitstr varchar (100)) - RETURns varchar (8000) Returns Intas Begin Declare @int_return int declare @start int declare @next int declare @Location int search @next = 0 select @Location = 1 if len (@str)