• [Sql Server][原创]


    -- 返回字符串以分隔符分隔的第n(1/2/3……)个字符换

    USE [EPICOR10]
    GO
    /****** Object:  UserDefinedFunction [dbo].[AH_Entry]    Script Date: 2017-12-23 16:30:39 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    /*
        改自:Ice.Entry(@idx int, @char_expr nvarchar(max), @delim nchar(1))
    
        select ice.Entry(1,'http://192.168.0.251/PackInfo/Tiger/FM/TG17/PC/Chest Strap/A1.jpg','Tiger/')
        select dbo.AH_Entry(2,'http://192.168.0.251/PackInfo/Tiger/FM/TG17/PC/Chest Strap/A1.jpg','Tiger/')
    
        select SubString(dbo.AH_Entry(dbo.AH_Num_Entries('http://192.168.0.251/PackInfo/Tiger/FM/TG17/PC/Chest Strap/A1.jpg','Tiger/'),'http://192.168.0.251/PackInfo/Tiger/FM/TG17/PC/Chest Strap/A1.jpg','Tiger/'),0,CharIndex('/',dbo.AH_Entry(dbo.AH_Num_Entries('http://192.168.0.251/PackInfo/Tiger/FM/TG17/PC/Chest Strap/A1.jpg','Tiger/'),'http://192.168.0.251/PackInfo/Tiger/FM/TG17/PC/Chest Strap/A1.jpg','Tiger/')))
    */
    
    ALTER function [dbo].[AH_Entry](@idx int, @char_expr nvarchar(max), @delim nvarchar(100))
    returns nvarchar(max)
    as
    begin
      declare @begin int, @end int, @count int
      declare @str nvarchar(max)
      set @count = 1
      set @begin = 1
      set @end = charindex(@delim, @char_expr)
      if @idx <= 0
        return (NULL)
      if (@end = 0) and @idx > 1
        return (NULL)
      if (@end = 0) and @idx = 1
        return @char_expr
      set @str = @char_expr
      while charindex(@delim, @str) > 0 and @count < @idx
      begin
        set @begin = charindex(@delim, @str) + len(@delim)
        set @str = substring(@str, @begin, len(@str) - @begin + 1)
        set @count = @count + 1
      end
      if @count < @idx
        return (NULL)
      if charindex(@delim, @str) > 0
        set @str = substring(@str, 1, charindex(@delim, @str) - 1)
      else
        set @str = substring(@str, 1, len(@str))
      return (@str)
    end

    -- 返回字符串以分隔符分隔的字符数

    USE [EPICOR10]
    GO
    /****** Object:  UserDefinedFunction [dbo].[AH_Num_Entries]    Script Date: 2017-12-23 16:35:01 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    /*
        改自:Ice.num_entries(@char_expr nvarchar(max), @delim nchar(1))
    
        select ice.num_entries('http://192.168.0.251/PackInfo/Tiger/FM/TG17/PC/Chest Strap/A1.jpg','Tiger/')
        select dbo.AH_Num_Entries('http://192.168.0.251/PackInfo/Tiger/FM/TG17/PC/Chest Strap/A1.jpg','Tiger/')
    
        select dbo.AH_Num_Entries('http://192.168.0.251/PackInfo/Tiger/FM/TG17/Tiger/PC/Chest Strap/A1.jpg','Tiger/')
    */
    
    
    ALTER function [dbo].[AH_Num_Entries](@char_expr nvarchar(max), @delim nvarchar(100))
    returns int
    as
    begin
      declare @begin int, @count int
      declare @str nvarchar(max)
      set @count = 1
      set @begin = 1
      if len(@char_expr) <= 0
        return (0)
      set @str = @char_expr
      while charindex(@delim, @str) > 0
      begin
        set @begin = charindex(@delim, @str) + len(@delim)
        set @str = substring(@str, @begin, len(@str) - @begin + 1)
        set @count = @count + 1
      end
      return (@count)
    end
    博客标明【原创】的文章都是本人亲自编写内容! 如有需要转载, 请标明出处:辉创1989(http://www.cnblogs.com/ahui1989/),届时非常感谢! 文章分享在此,希望我之原创有帮到你们! 如有不足之处也可联系我,以便我们共同探讨! 本人现职为Epicor10 系统 开发维护工作,如有需要可共同探讨相关技术知识及经验总结! QQ:929412592
  • 相关阅读:
    游标第一次应用
    HttpWebRequest的GetResponse或GetRequestStream偶尔超时 + 总结各种超时死掉的可能和相应的解决办法
    npoi导出excel(模板)插入图片,文本只读,不可以修改
    npoi导出excel(模板)
    iis7 发布mvc 遇到的HTTP错误 403.14-Forbidden Web 服务器被配置为不列出此目录的内容
    如何成为一个糟糕的程序员
    Mutiselect下拉复选框(保存和设置默认选中项)
    Android UI 绘制过程浅析(三)layout过程
    Android UI 绘制过程浅析(二)onMeasure过程
    [EventBus源码解析] 订阅者处理消息的四种ThreadMode
  • 原文地址:https://www.cnblogs.com/ahui1989/p/8093754.html
Copyright © 2020-2023  润新知