SQL中自己创建函数,分割字符串
2008-04-26 23:32
549 查看
----------------------------------------------------------------
/**
* 版权: 石太祥[E.Alpha] 所有;
*
* email: ealpha(AT)msn(DOT)com ;
* msn:ealpha(AT)msn(DOT)com ;
* :9690501
*
* 所有转载请注明本信息!
*/
----------------------------------------------------------------
ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[getEPnum]')andxtypein(N'FN',N'IF',N'TF'))
dropfunction[dbo].[getEPnum]
GO
ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[getstrcount]')andxtypein(N'FN',N'IF',N'TF'))
dropfunction[dbo].[getstrcount]
GO
ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[getstrofindex]')andxtypein(N'FN',N'IF',N'TF'))
dropfunction[dbo].[getstrofindex]
GO
SETQUOTED_IDENTIFIERON
GO
SETANSI_NULLSON
GO
--- 这个函数直接调用了另外的两个函数,可以先阅读下面提到的两个函数
CREATE function getEPnum (@str varchar(8000))
returns varchar(8000)
as
begin
declare @str_return varchar(8000)
declare @i int
declare@temp_iint
declare@onlineornotint
declare@findepnumokint
--用来取得一个epnum,
--规则:首先从chatid中取,如果有在线得,则取得最前面得在线得返回
-- 如果全部不在线,则返回‘00000000’
select@findepnumok=0
select@temp_i=0
IFlen(@str)<=0
begin
SELECT@str_return='00000000'
end
else
begin
select@i=dbo.getstrcount(@str,',')
WHILE@temp_i<@i
BEGIN
select@onlineornot=onlinefromwwchat_userwhereepnum=dbo.getstrofindex(@str,',',@temp_i)
IF(@onlineornot=1)
begin
select@str_return=dbo.getstrofindex(@str,',',@temp_i)
select@findepnumok=1--找到epnum后置为1
BREAK
end
ELSE
begin
select@temp_i=@temp_i+1
select@findepnumok=0--找不到epnum后置为1共3页 第1页
/**
* 版权: 石太祥[E.Alpha] 所有;
*
* email: ealpha(AT)msn(DOT)com ;
* msn:ealpha(AT)msn(DOT)com ;
* :9690501
*
* 所有转载请注明本信息!
*/
----------------------------------------------------------------
ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[getEPnum]')andxtypein(N'FN',N'IF',N'TF'))
dropfunction[dbo].[getEPnum]
GO
ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[getstrcount]')andxtypein(N'FN',N'IF',N'TF'))
dropfunction[dbo].[getstrcount]
GO
ifexists(select*fromdbo.sysobjectswhereid=object_id(N'[dbo].[getstrofindex]')andxtypein(N'FN',N'IF',N'TF'))
dropfunction[dbo].[getstrofindex]
GO
SETQUOTED_IDENTIFIERON
GO
SETANSI_NULLSON
GO
--- 这个函数直接调用了另外的两个函数,可以先阅读下面提到的两个函数
CREATE function getEPnum (@str varchar(8000))
returns varchar(8000)
as
begin
declare @str_return varchar(8000)
declare @i int
declare@temp_iint
declare@onlineornotint
declare@findepnumokint
--用来取得一个epnum,
--规则:首先从chatid中取,如果有在线得,则取得最前面得在线得返回
-- 如果全部不在线,则返回‘00000000’
select@findepnumok=0
select@temp_i=0
IFlen(@str)<=0
begin
SELECT@str_return='00000000'
end
else
begin
select@i=dbo.getstrcount(@str,',')
WHILE@temp_i<@i
BEGIN
select@onlineornot=onlinefromwwchat_userwhereepnum=dbo.getstrofindex(@str,',',@temp_i)
IF(@onlineornot=1)
begin
select@str_return=dbo.getstrofindex(@str,',',@temp_i)
select@findepnumok=1--找到epnum后置为1
BREAK
end
ELSE
begin
select@temp_i=@temp_i+1
select@findepnumok=0--找不到epnum后置为1共3页 第1页
相关文章推荐
- SQL 中自己创建函数,分割字符串
- SQL 创建函数的样例(按指定的符号分割字符串,并返回临时表)
- 自己写的分割字符串的函数
- 在sql中实现字符串分割(函数)
- C语言strtok()函数:分割字符串(自己实现strtok)
- SQL 字符串分割函数
- T-SQL 定义分割字符串的函数
- 今天看到一个blog上讨论字符串分割函数,一时兴起,自己写了一个
- T-SQL 定义分割字符串的函数
- Oracle 创建一个字符串分割的函数
- SQL语句--一个简单的字符串分割函数
- sql 用函数来分割字符串
- sql语句 自己编写一个函数reversion,完成颠倒一个字符串,即:select dbo.reversion('abcd') 输出的结果为 dcba
- T-SQL 定义分割字符串的函数
- T-SQL 定义分割字符串的函数
- substr 和 find函数实现自己的字符串分割函数(以指定分隔符分割字符串,分隔符可为字符串)
- SQL 常用字符串操作函数 分割 合并 取值
- SQL点滴3—一个简单的字符串分割函数
- sql 分割字符串 自定义函数