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',',')
  • 相关阅读:
    个人所得税避税的10种方法
    营业税
    融资租赁
    会计等式
    公司公积金
    fixed语句
    自由之路
    $or操作符
    $in 操作符
    Redis 字典的实现
  • 原文地址:https://www.cnblogs.com/codeDevotee/p/11349038.html
Copyright © 2011-2022 走看看