SQL Server SPLIT

Source: Internet
Author: User

CREATE FUNCTIONDbo. SPLIT (@Long_str NVARCHAR(MAX),@split_str NVARCHAR( -))    RETURNS  @tmp TABLE(IDInT     IDENTITY PRIMARY KEY, Short_strNVARCHAR(MAX)    )     as   BEGIN       DECLARE @short_str NVARCHAR(MAX),@split_str_length int,@split_str_Position_Begin int    SET @split_str_length = LEN(@split_str)     SET @Long_str=REPLACE(REPLACE(@Long_str,CHAR(Ten),"'),CHAR( -),"')    IF CHARINDEX(@split_str,@Long_str)=1          SET @Long_str=STUFF(@Long_str,1,@split_str_length,"')    IF CHARINDEX(@split_str,@Long_str)=0        INSERT  into @tmp SELECT @Long_str     ELSE        BEGIN             while 1>0                    BEGIN                       SET @split_str_Position_Begin = CHARINDEX(@split_str,@Long_str)                    SET @short_str=left(@Long_str,@split_str_Position_Begin-1)                     IF @short_str<>"' INSERT  into @tmp SELECT @short_str                      SET @Long_str=STUFF(@Long_str,1,@split_str_Position_Begin+@split_str_length-1,"')                    SET @split_str_Position_Begin = CHARINDEX(@split_str,@Long_str)                    IF @split_str_Position_Begin=0                     BEGIN                        IF LTRIM(@Long_str)<>"'                            INSERT  into @tmp SELECT @Long_str                          Break                    END                END                   END    RETURN     ENDGO
SELECT  from Dbo. SPLIT ('A-st', ',')

SQL Server SPLIT

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.