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
)
As
Begin
Declare @ object_id nvarchar (500)
Declare @ I int
Declare @ Len int
Print @ string
If (@ string is null) or (ltrim (@ string) = '')
Return
-- Check whether the string @ string contains the @ splitstring character.
While charindex (@ splitstring, @ string)> 0
Begin
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
End
Set @ object_id = @ string
-- Insert into a (ID) values (@ object_id) -- modify the SQL statement as needed.
End
Go
Exec sp_split_string '200 ',','