SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Faking Multidimensional Arrays in T-SQL made easy!


Faking Multidimensional Arrays in T-SQL made easy!

Author
Message
stax68
stax68
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1156 Visits: 43
Jeff Moden (11/4/2008)
Keep it clean, slick. Wink


Oh, I do - mens sana in corpore sano old chap.

And, don't blame me if you don't understand what I'm saying. w00t


in that case may I congratulate you on your magnificent imperial robe!

Tim Wilkinson

"If it doesn't work in practice, you're using the wrong theory"
- Immanuel Kant
Joshua M Perry
Joshua M Perry
Mr or Mrs. 500
Mr or Mrs. 500 (584 reputation)Mr or Mrs. 500 (584 reputation)Mr or Mrs. 500 (584 reputation)Mr or Mrs. 500 (584 reputation)Mr or Mrs. 500 (584 reputation)Mr or Mrs. 500 (584 reputation)Mr or Mrs. 500 (584 reputation)Mr or Mrs. 500 (584 reputation)

Group: General Forum Members
Points: 584 Visits: 550
This is great. Going back to using the concept of a stack and heap. This is way faster than using a cursor to pivot data. Now if you could just find a way to run SQL Server on a MOS 6502...

Joshua Perry
http://www.greenarrow.net
Randal Burke
Randal Burke
Grasshopper
Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)Grasshopper (21 reputation)

Group: General Forum Members
Points: 21 Visits: 26
Joshua Perry (11/4/2008)
This is great. Going back to using the concept of a stack and heap. This is way faster than using a cursor to pivot data. Now if you could just find a way to run SQL Server on a MOS 6502...


Well,
Since you asked... the MOS6502 WAS able to run a cross-assembled version of CP/M, from which DOS was built.

Then Windows 1 was first brought out on an Apple //e (without using the Z80 card) - then came the Microsoft Z-80 card with Windows 3.0... and now we have advanced all the way up to having Windows Compact which runs on... OMG!!! those pesky little microprocessors with only a few megs of program space and then those wonderful little plug-in memory sticks that we call PDA!

What goes around definitely comes back. Smile

Everything old is new again!
ians
ians
Say Hey Kid
Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)Say Hey Kid (668 reputation)

Group: General Forum Members
Points: 668 Visits: 79
mmcclure (11/4/2008)
Okay, corrected the code for SQL 2008 (at least this is what worked for me).

/* create the basic table structures needed */
CREATE TABLE [X_DIMENSION]
( [LOC] [int] NULL , [X_ELEMENT] [varchar] (2000) NULL )

CREATE TABLE [Y_DIMENSION]
( [LOC] [int] NULL, [Y_ELEMENT] [varchar] (2000) NULL )

CREATE TABLE [X_Y_INDEX] ( X_LOC [int] NULL, Y_LOC [int] NULL )

/* Now we create some data to place into the tables, indexed */
INSERT X_Y_INDEX (X_LOC, Y_LOC)SELECT 5,7
INSERT X_DIMENSION (LOC,X_ELEMENT)SELECT 5,'DATA IN ELEMENT 5 '
INSERT Y_DIMENSION (LOC,Y_ELEMENT)SELECT 7,'REMAINING
DATA FOR ELEMENT 5,7'

DECLARE @X INT, @Y INT

SET @X = 5 -- or whatever method of loading you wantSET @Y = 7

SELECT A.X_ELEMENT + B.Y_ELEMENT FROM X_DIMENSION A, Y_DIMENSION B WHERE A.LOC = @X AND B.LOC = @Y

/* The Query returns the concatenated value! */
/* DATA IN ELEMENT 5, REMAINING DATA IN ELEMENT 7*/


Still pointless. Why use the X_Y_INDEX table, your not using it as part of the retreive, so why have it.

If you think this all works, show us how you would store a second independant, seperate item in element (5,8).

I'm astounded this got past any approval/editing process.



Lynn Pettis
Lynn Pettis
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41498 Visits: 38567
Randal Burke (11/4/2008)

2) Captain Kirk once said, in his final battle with Khan - "He is evidencing classic two dimensional thinking" - we all evidence that quite often.


I would have sworn that it was Spock who made this comment...

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)

Group: General Forum Members
Points: 91204 Visits: 41151
stax68 (11/4/2008)
Jeff Moden (11/4/2008)
Keep it clean, slick. Wink


Oh, I do - mens sana in corpore sano old chap.

And, don't blame me if you don't understand what I'm saying. w00t


in that case may I congratulate you on your magnificent imperial robe!


Wow... tough crowd, Tim. Wink

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Lynn Pettis
Lynn Pettis
SSC-Forever
SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)SSC-Forever (41K reputation)

Group: General Forum Members
Points: 41498 Visits: 38567
Here is the actual quote from movie:

He is intelligent, but not experienced. His pattern indicates 2 dimensional thinking. -- Spock


Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
David in .AU
David in .AU
SSChasing Mays
SSChasing Mays (618 reputation)SSChasing Mays (618 reputation)SSChasing Mays (618 reputation)SSChasing Mays (618 reputation)SSChasing Mays (618 reputation)SSChasing Mays (618 reputation)SSChasing Mays (618 reputation)SSChasing Mays (618 reputation)

Group: General Forum Members
Points: 618 Visits: 561

I read it the first time. You seemed to say (and therefore like it or not did say) it was about 3D arrays, but the author didn't go far enough in his explanation.


From what I read of Jeff's comment it was the other way around, that the article didnt go far enough and should have included 3D arrays to further explain the process.

And is there a full moon about somewhere, there seems to be so many agressive comments about this post...
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)SSC Guru (91K reputation)

Group: General Forum Members
Points: 91204 Visits: 41151
Spot-on, David.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
stax68
stax68
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1156 Visits: 43
David B (11/4/2008)

I read it the first time. You seemed to say (and therefore like it or not did say) it was about 3D arrays, but the author didn't go far enough in his explanation.


From what I read of Jeff's comment it was the other way around, that the article didnt go far enough and should have included 3D arrays to further explain the process.

And is there a full moon about somewhere, there seems to be so many agressive comments about this post...


Well, OK but 'far enough in Xing' to me means Xing, but not far enough.

Re aggression - lots of criticism, certainly, along with a bit of robust badinage between Mr Moden and myself. Perhaps more emoticons needed to add some passivity, eh? Wink

Tim Wilkinson

"If it doesn't work in practice, you're using the wrong theory"
- Immanuel Kant
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search