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

Create a Tally or Numbers Table Expand / Collapse
Author
Message
Posted Monday, July 13, 2009 5:58 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, March 11, 2014 6:39 PM
Points: 25, Visits: 66
I prefer to use "Number" (one-based) so that I can distinguish it from "WholeNumber" which is zero-based. The column name I used for both tables is "value".
Post #752404
Posted Tuesday, July 14, 2009 4:59 AM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Yesterday @ 7:56 PM
Points: 36,775, Visits: 31,230
I'd have a hard time doing that because Number is a reserved word but to each their own. Also, are you implying that you have two separate tables? One for one-based and the other for zero-based? If so and if the use of BETWEEN is a pain, why not just have a single table starting at zero and a pass-through view with a >0 criteria? The underlying clustered index would still be used in either case.

Also, although I appreciate why you called your tables what you did and why, would it not be less confusing to casual users of your system to call one-based Number1 and zero-based Number0?


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

(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 #752572
Posted Tuesday, July 14, 2009 5:09 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Tuesday, March 11, 2014 6:39 PM
Points: 25, Visits: 66
I didn't think of them but now that you pointed them out, you are right on both observations.

1. A single table starting at zero and a pass-through view with a >0 critiera.
2. Number1 and Number0 would be easier for casual user.


>if the use of BETWEEN is a pain
I'm curious how you would use BETWEEN when you need a zero-based number table.
Post #753113
Posted Tuesday, July 14, 2009 7:08 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Yesterday @ 7:56 PM
Points: 36,775, Visits: 31,230
What I meant by the BETWEEN was, if you have a zero-based table and need a unit-based solution, then the WHERE clause would need to include WHERE N BETWEEN 1 AND @DesiredInt. That would also allow you to use just a single table.

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

(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 #753131
Posted Thursday, November 24, 2011 4:39 PM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 7:44 AM
Points: 76, Visits: 379
Jeez Jeff, I knew you'd been doing Tally tables for a long time, but you wrote the article THAT long ago ?
Talk about nativity ...
Post #1211764
Posted Thursday, November 24, 2011 5:09 PM


SSC-Dedicated

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

Group: General Forum Members
Last Login: Yesterday @ 7:56 PM
Points: 36,775, Visits: 31,230
ben.mcintyre (11/24/2011)
Jeez Jeff, I knew you'd been doing Tally tables for a long time, but you wrote the article THAT long ago ?
Talk about nativity ...




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

(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 #1211767
« Prev Topic | Next Topic »

Add to briefcase «««1234

Permissions Expand / Collapse