0% found this document useful (0 votes)
2 views1 page

SQLArray 2

Using SQL to generate Array

Uploaded by

HangYang
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

SQLArray 2

Using SQL to generate Array

Uploaded by

HangYang
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

--Prepare values fro array

Declare @j as int
Declare @ini as varchar(max)
set @j = 1
while @j <= 100
begin
set @ini = 'insert into A values('+ convert(varchar(max),rand()) + ',' + convert
(varchar(100),@j)+')'
exec(@ini)
set @j = @j + 1
end;
--initialize array/tree
declare @i as int
declare @str as varchar(max)
set @i = 1
--set @str = (
while @i <= 100
begin
set @str = 'Declare @v'+convert(varchar(100),@i)+' as varchar(max) set @v'+ conv
ert(varchar(100),@i)+' = (select val
from a where idx = ' + convert(varchar(100),@i)+ ')'
exec(@str)
set @i = @i + 1
continue
end

You might also like