SQL也可以实现split函数
2012-11-06 09:44
302 查看
复制以下代码在查询里执行就可以啦。
使用办法:select dbo.split(parentpath, ',', 1)
(’字段|字段|字段‘,'|',取出那一段从0开始)
使用办法:select dbo.split(parentpath, ',', 1)
(’字段|字段|字段‘,'|',取出那一段从0开始)
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO 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
相关文章推荐
- sql实现split函数的脚本
- sql语句like的用法 有些正则表达式可以通过like实现
- sql实现split函数的脚本
- SQL实现split函数,自定义分割字符,自定义取出第几个分割字符前的字符串
- SQL 实现split函数的功能
- SQL实现split函数,自定义分割字符,自定义取出第几个分割字符前的字符串
- Sql字符串分组Split函数的两种实现方法(转)
- 【SQL】在数据库中做出判断,改变要显示的内容,case when可以做到,oracle中实现
- [es-sql] 不支持distinct去重,可以用group by来实现
- SQL实现split函数,自定义分割字符,自定义取出第几个分割字符前的字符串
- ms sql server中实现的unix时间戳函数(含生成和格式化,可以和mysql兼容)
- PL/SQL INSTR、SUBSTR和split函数实现
- Sql字符串分组Split函数的两种实现方法
- SQL 实现Split函数
- 动态SQL的执行,注:exec sp_executesql 其实可以实现参数查询和输出参数的
- SqlDataAdapter可以用SqlCommandBuilder 实现批量更新
- 在SQL语句中实现split函数 zt
- 在SQL语句中实现split函数
- SQL实现split函数,自定义分割字符,自定义取出第几个分割字符前的字符串
- [转][SQL]如何实现存储过程中动态加入条件---没想到语句可以这么巧妙