Alternatives to Arrays

Download the Code iconT-SQL doesn't support arrays (groups of objects that have the same attributes and that you can use techniques such as subscripting to address individually). But you can use local or global temporary tables, which the main article describes, as an alternative to an array. The accessibility requirements of your pseudo array will determine whether you should create it as a global temporary table—accessible to all connections in all scopes—or as a local temporary table—accessible only to the creating connection from the creating scope (and any inner scopes).

For example, to create a one-dimensional pseudo array, available only to your connection, with 10 integer members initialized to NULL, execute the code that Listing A shows. To create a two-dimensional pseudo array with 200 members, execute the code that Listing B shows. The output from Listing B is 100. You can use UPDATE statements to set the values of the pseudo array's members. You can also retrieve a member's value and store it in a local variable, as the code in Listing C shows.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.