SQL custom Functions, separators

Source: Internet
Author: User

--------------establishing a stored procedure

CREATE function [dbo]. [Split]

(

@str varchar (4500),

@sep varchar (1)

)

Returns @t table (id int identity (), Col varchar (4500))

As

Begin

--Defines the current position, delimiter start and string length, and the currently acquired string

declare @posi int, @start int, @str_leg int, @gchar varchar (2), @mingzhong int

Set @str_leg =len (@str)

Set @posi =0

Set @start =0

Set @mingzhong =0

while (@posi <[email Protected]_leg)

Begin

Set @gchar =substring (@str, @posi, 1)

if (@[email protected])

Begin

INSERT into @t values (substring (@str, @start +1,@[email protected])

Set @[email protected]

End

Set @[email protected]+1

End

Return

End

------------execution to: query results for delimiters

SELECT * from Dbo.split (' 234;32423;; 2342;a;b;234234;23, ', '; ')

SQL custom Functions, separators

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.