Stored Procedure Processing Array

Source: Internet
Author: User

 

1 create procedure sp_split_string
2 (
3 @ string nvarchar (4000)
4)
5
6 begin
7 declare @ object_id nvarchar (500)
8 declare @ I int
9 declare @ Len int
10 print @ string
11 if (@ string is null) or (ltrim (@ string) = '')
12 Return
13
14 While charindex (',', @ string)> 0
15 begin
16 set @ Len = Len (@ string)
17 set @ I = charindex (',', @ string)
18 set @ object_id = left (@ string, @ i-1)
19 insert into a (ID) values (@ object_id) -- modify the SQL statement as needed.
20 set @ string = right (@ string, @ len-@ I)
21 End
22 set @ object_id = @ string
23 insert into a (ID) values (@ object_id) -- modify the SQL statement as needed.
24 end
25 go
26
27
28 -- Test
29 Create Table
30 (
31 ID int
32)
33 select * from
34 exec sp_split_string '123'
35 select * from a transmits an array string to the stored procedure (and processes the Stored Procedure string)
36

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.