=波波日志 > SQL及数据库 > SQL实现split函数,自定义分割字符,自定义取出第几个分割字符前的字符串=
[转]SQL实现split函数,自定义分割字符,自定义取出第几个分割字符前的字符串
+展开
-SQL
CREATE FUNCTION [dbo].[split]
(@str nvarchar(4000),@code varchar(10),@no int )
RETURNS varchar(200)
AS
BEGIN
declare @intLen int
declare @count int
declare @indexb int
declare @indexe int
set @intLen=len(@code)
set @count=0
set @indexb=1
if @no=0
if charindex(@code,@str,@indexb)<>0
return left(@str,charindex(@code,@str,@indexb)-1)
else
return @str
while charindex(@code,@str,@indexb)<>0
begin
set @count=@count+1
if @count=@no
break
set @indexb=@intLen+charindex(@code,@str,@indexb)
end
if @count=@no
begin
set @indexe=@intLen+charindex(@code,@str,@indexb)
if charindex(@code,@str,@indexe)<>0
return substring(@str,charindex(@code,@str,@indexb)+len(@code),charindex(@code,@str,@indexe)-charindex(@code,@str,@indexb)-len(@code))
else
return right(@str,len(@str)-charindex(@code,@str,@indexb)-len(@code)+1)
end
return ''
END
(@str nvarchar(4000),@code varchar(10),@no int )
RETURNS varchar(200)
AS
BEGIN
declare @intLen int
declare @count int
declare @indexb int
declare @indexe int
set @intLen=len(@code)
set @count=0
set @indexb=1
if @no=0
if charindex(@code,@str,@indexb)<>0
return left(@str,charindex(@code,@str,@indexb)-1)
else
return @str
while charindex(@code,@str,@indexb)<>0
begin
set @count=@count+1
if @count=@no
break
set @indexb=@intLen+charindex(@code,@str,@indexb)
end
if @count=@no
begin
set @indexe=@intLen+charindex(@code,@str,@indexb)
if charindex(@code,@str,@indexe)<>0
return substring(@str,charindex(@code,@str,@indexb)+len(@code),charindex(@code,@str,@indexe)-charindex(@code,@str,@indexb)-len(@code))
else
return right(@str,len(@str)-charindex(@code,@str,@indexb)-len(@code)+1)
end
return ''
END
该文章转载自德仔工作室:http://www.dezai.cn/Article_Show.asp?ArticleID=17972&ArticlePage=2
类别:SQL及数据库 作者:转载 日期:2009-06-29 【评论:0】
相关文章
暂时没有评论!
发表留言
热门博文
- access数据库导入mssqlserver保留自动增长列
- mssqlserver数据库导入access保留自动增长列
- 无法连接到WMI提供程序。你没有权限或者该服务器无法访问
- 链接Access出现“找不到可安装的 ISAM”错误的问题
- asp连接mssql“出现未找到提供程序。该程序可能未正确安装”错误
- Windows7如何安装SQL Server 2000
最新博文
- Sql Server参数化优化查询
- sqldataadapter update更新dataset无法同时更新多个表
- SqlServer2000无法打开用户默认数据库。登录失败
- sqlserver2005如何转移到sqlserver2000
- 'sa'用户登录失败。原因:未与信任 SQL Server 连接相关联
- SQL Server 2005 无法连接
随机博文
- mysql5.1事件调度器
- 压缩MS SQL SERVER 2000数据库日志
- mssql性能优化(教你写出高质量的SQL语句)(一)
- SQL Server 2000 中使用正则表达式
- Sqlserver存储过程 加密、解密方法
- SQL Server的备份还原功能之二:主要备份类型
广告商赞助

