Multidimensional Arrays

Because array elements can store nearly any type of data, they can also store handles to other arrays. This means that you can easily set up multidimensional arrays and that these arrays can be of either the jagged or the smooth variety. Here's an example:

 DECLARE @yhdl int, @xhdl int, @xsiz int, @ysiz int, @res int, @xcnt int, @ycnt int SELECT @ysiz=20, @xsiz=10 -- Allocate the y dimension SET @yhdl=fn_createarray(@ysiz) -- Allocate and fill each row SET @ycnt=1 WHILE @ycnt<=@ysiz BEGIN SET @xhdl=fn_createarray(@xsiz) SET @res=fn_setarray(@yhdl,@ycnt,@xhdl) SET @xcnt=1 WHILE @xcnt<=@xsiz BEGIN SET @res=fn_setarray(@xhdl,@xcnt,RAND()*100) SET @xcnt=@xcnt+1 END SET @ycnt=@ycnt+1 END -- List each row SET @ycnt=1 WHILE @ycnt<=@ysiz ...

Get Guru's Guide to SQL Server™ Stored Procedures, XML, and HTML, The now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.