Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays in T-SQL? 1

Status
Not open for further replies.

Waynest

Programmer
Jun 22, 2000
321
GB
Hi

I think I am correct in saying that you can't declare an array of variables in T-SQL?

So how do you avoid massive duplication of code where you have to perform a loop 100+ times storing the results from each iteration?

There must be a workaround???

Thanks
 
Waynest,

there aren't arrays as such but there are workarounds


Code:
declare @myArray table (id int , myValue char(10))

declare @cnt  int
set @cnt = 0

while @cnt < 10
	begin
		set @cnt = @cnt + 1
		insert into @myArray 
		values(@cnt, cast(@cnt as char(10)))
	end

select * from @myArray

Glyndwr
 
As as side note, Microsoft has recanted the use of table variables over temp tables that will be used with larger record sets. I will post the link as soon as I am able to relocate it. In saying this, your solution may need to be re-evaluated.

Thanks

J. Kusch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top