Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««1234»»

Faking Multidimensional Arrays in T-SQL made easy! Expand / Collapse
Author
Message
Posted Tuesday, November 04, 2008 1:30 PM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Tuesday, December 22, 2009 8:22 AM
Points: 696, Visits: 42
Jeff Moden (11/4/2008)
Keep it clean, slick. ;)


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

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


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
Post #596877
Posted Tuesday, November 04, 2008 1:34 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Thursday, February 06, 2014 9:39 AM
Points: 420, Visits: 487
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.usesage.com
Post #596878
Posted Tuesday, November 04, 2008 1:42 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, June 01, 2009 7:27 AM
Points: 3, 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. :)

Everything old is new again!
Post #596885
Posted Tuesday, November 04, 2008 2:33 PM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Thursday, July 22, 2010 9:06 AM
Points: 632, 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.



Post #596919
Posted Tuesday, November 04, 2008 3:29 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 8:55 PM
Points: 22,492, Visits: 30,199
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...



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)
Post #596949
Posted Tuesday, November 04, 2008 3:30 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 11:47 PM
Points: 35,959, Visits: 30,252
stax68 (11/4/2008)
Jeff Moden (11/4/2008)
Keep it clean, slick. ;)


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

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


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


Wow... tough crowd, Tim. ;)


--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."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #596951
Posted Tuesday, November 04, 2008 3:35 PM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Yesterday @ 8:55 PM
Points: 22,492, Visits: 30,199
Here is the actual quote from movie:

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





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)
Post #596957
Posted Tuesday, November 04, 2008 4:05 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Tuesday, January 14, 2014 1:56 PM
Points: 522, Visits: 553

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...
Post #596968
Posted Tuesday, November 04, 2008 4:14 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 11:47 PM
Points: 35,959, Visits: 30,252
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."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #596973
Posted Tuesday, November 04, 2008 4:36 PM
Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Tuesday, December 22, 2009 8:22 AM
Points: 696, Visits: 42
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? ;)




Tim Wilkinson

"If it doesn't work in practice, you're using the wrong theory"
- Immanuel Kant
Post #596982
« Prev Topic | Next Topic »

Add to briefcase «««1234»»

Permissions Expand / Collapse