Arrays in SQL Server

Source: Internet
Author: User
SQL Server 2005 does not contain arrays, but we can use strings separated by commas to replace them.

 
Create proc testarray
@ Array varchar (max)
As
Begin
If (right (@ array, 1) <> ',') -- ensure that the rightmost is a comma.
Set @ array = @ array + ','

Declare @ start int -- the position where each screenshot starts
Declare @ temp int -- the final position of each clip
Declare @ totallength int -- total length of the input string

Set @ totallength = Len (@ array)
Set @ start = 0;
Set @ temp = 0;

While (@ start <@ totallength) -- if not
Begin
If (substring (@ array, @ temp, 1) = ',') -- test whether the next character is a comma
Begin
Print substring (@ array, @ start, @ temp-@ start) -- If yes, It is intercepted from the last comma
Set @ start = @ temp + 1 -- Update start point, skip the comma
End

Set @ temp = @ temp + 1 -- forward into one
End
End

 

ReferenceArticle:

SQL Server 2005 stored procedures do not support array-type parameters

Http://www.cnblogs.com/zys529/archive/2009/02/28/1400258.html

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.