Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Tim
Starting Member
392 Posts |
Posted - 2002-05-12 : 20:32:35
|
| I have the following table which represents storage boxes. A box is dived into 'cells' represented by three co-ordinates Aisle, Row and Tier (which kind of correspond to length, width and depth positions).CREATE TABLE box (BoxID int NOT NULL IDENTITY,NbrAisles int NOT NULL ,NbrRows int NOT NULL ,NbrTiers int NOT NULL )-- assume boxID = 1INSERT INTO box (NbrAisles, NbrRows, NbrTiers) VALUES (2,3,1)-- assume boxID = 2INSERT INTO box (NbrAisles, NbrRows, NbrTiers) VALUES (2,2,2)I want to make a view that represents a table of all "cells" in each box:BoxID Aisle Row Tier----- ----- --- ----1 1 1 11 1 2 11 1 3 11 2 1 11 2 2 11 2 3 12 1 1 12 1 1 22 1 2 12 1 2 22 2 1 12 2 1 22 2 2 12 2 2 2It's got to be a view and no additional tables. Is it possible even? |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2002-05-12 : 21:47:59
|
You can use a tally or sequence table to generate the values you need. Here's some background on tally/sequence tables:http://www.sqlteam.com/item.asp?ItemID=5857http://www.sqlteam.com/item.asp?ItemID=2652http://www.sqlteam.com/item.asp?ItemID=3332Basically it's just a simple table with sequential numbers in it, and you could write a view to generate the results like this:CREATE VIEW AllCells ASSELECT B.ID BoxID, A.ID Aisle, R.ID Row, T.ID TierFROM Box B, Tally A, Tally R, Tally TWHERE A.ID<=B.NbrAislesAND R.ID<=B.NbrRowsAND T.ID<=B.NbrTiersAnd of course, you can do a bunch of other things with the tally table as well |
 |
|
|
|
|
|
|
|