Pai_^ string-separated function SQL

Source: Internet
Author: User
In the previous article, it was not mentioned in sorting ~~ I see the code from the ASP. NET knowledge base. This is also an analysis.
/Files/ajaxren/separator string .rar

Alter procedure sp_split_string
@ String nvarchar (4000), -- string to be split
@ Splitstring varchar (2000) -- delimiter in the middle
Declare @ object_id nvarchar (500)
Declare @ I int
Declare @ Len int
Print @ string
If (@ string is null) or (ltrim (@ string) = '')
-- Check whether the string @ string contains the @ splitstring character.
While charindex (@ splitstring, @ string)> 0
Set @ Len = Len (@ string) -- total length
Print @ Len
Set @ I = charindex (@ splitstring, @ string) -- locate the first place that contains the delimiter.
Print @ I
Set @ object_id = left (@ string, @ i-1) -- truncate start to split the previous data (split data) -- start on the right
Print 'object _ id = '+ @ object_id
-- Insert into a (ID) values (@ object_id) -- modify the SQL statement as needed.
Set @ string = right (@ string, @ len-@ I) -- copy data from the variable-from the end of the delimiter to the entire length-right is calculated from the left
Set @ object_id = @ string
-- Insert into a (ID) values (@ object_id) -- modify the SQL statement as needed.

Exec sp_split_string '200 ',','

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: 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.