Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 array of variables

Author  Topic 

andryi
Starting Member

17 Posts

Posted - 2009-10-07 : 12:40:20
Hi all, how can I have an array of variables,
I mean, how can create one variable by each row
in a table

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2009-10-07 : 12:50:01
There is not an array construct in the T-SQL language. Perhaps if you can elaborate on what you would like to accomplish, someone can offer some insight.

=======================================
Few things are harder to put up with than the annoyance of a good example. (Mark Twain)
Go to Top of Page

andryi
Starting Member

17 Posts

Posted - 2009-10-07 : 12:58:15
thank's for answer Bustaz Kool, well for example
If I have this
create table Client(
ID int,
name varchar(50),
direction varchar(50),
description varchar(50),
)
So, I have 4 columns of the table Client
and I'd like to have for variables
@Id int,name varchar(50),direction varchar(50),description varchar(50)
but with an array I supposed because, if other table have 10 columns
I want that array(suppously), can create 10 variables of the 10 columns of this table

So, how can I do it?
Go to Top of Page

andryi
Starting Member

17 Posts

Posted - 2009-10-07 : 13:00:46
or in another case, If I have a table with 4 rows
How can I create 1 variable by each row
Go to Top of Page

andryi
Starting Member

17 Posts

Posted - 2009-10-07 : 13:08:23
mmmm more clear, is this:

select ROW_NUMBER() OVER (ORDER BY name ) AS [ROW_NUMBER],
name from syscolumns where id=object_id('TableName')

and I have this:

ROW_NUMBER | name
---------------------
1 | code
2 | name
3 | description
4 | detail

so I have the name of the column of the table and an "index"
my question is, how can pass each 'name of column' to one variable distinct of other

like this:
code--->@code
name--->@name
description--->@description
detail--->@detail

but without create the variables one by one manually

Go to Top of Page
   

- Advertisement -