SQL Server imports an array to the stored procedure

Source: Internet
Author: User

Suppose I have an array: A (1) = 111, A (2) = 222, A (3) = 333 ......
W I want to pass the array into the stored procedure, but sqlserver does not support arrays. Search for Baidu and find a strong method:
1. First convert the array into a string separated by commas ,...... '
2. Convert the string into a SELECT statement connected with union:
Select '000000' as a Union select '000000' as a Union select '000000' as a Union select '000000' as ......
The statement returns the following results:
A
----------
111
222
333
444
.
.
.
.

Insert the result to the temporary table.

Declare @ string varchar (80)
Declare @ sqlstr2table varchar (1000)

Set @ string = '000000'

Set @ sqlstr2table = 'select' + Replace (@ string, ',', ''' as caller_id Union select ''') + ''''
Exec (@ sqlstr2table)

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.