zoukankan      html  css  js  c++  java
  • sql server split切割字符串

    create FUNCTION [dbo].[dnt_split]
    (
     @splitstring varchar(max),
     @separator CHAR(1) = ','
    )
    RETURNS @splitstringstable TABLE
    (
     [item] VARCHAR(200)
    )
    AS
    BEGIN
        DECLARE @currentindex INT
        DECLARE @nextindex INT
        DECLARE @returntext VARCHAR(200)
    
        SELECT @currentindex=1
    
        WHILE(@currentindex<=datalength(@splitstring))
        BEGIN
            SELECT @nextindex=charindex(@separator,@splitstring,@currentindex)
            IF(@nextindex=0 OR @nextindex IS NULL)
                SELECT @nextindex=datalength(@splitstring)+1
            
            SELECT @returntext=substring(@splitstring,@currentindex,@nextindex-@currentindex)
    
            INSERT INTO @splitstringstable([item])
            VALUES(@returntext)
            
            SELECT @currentindex=@nextindex+1
        END
        RETURN
    END

    调用方法:

    select * from dbo.dnt_split('123,123',',')
  • 相关阅读:
    poj2229 Sumsets (递推)
    hihocoder1148 February 29(区间闰年计数)
    sort函数比较cmp写法
    字符串忽略大小写
    地形
    启用和禁用warning
    AppStore SDK
    NGUI List优化
    ETC1
    加载
  • 原文地址:https://www.cnblogs.com/codeDevotee/p/11349038.html
Copyright © 2011-2022 走看看