January 21, 2011 at 11:46 pm
Anybody know of a good alternative for a "tally table" on SQL Azure? Like most things useful, this is not supported on SQL Azure:
SELECT Number N FROM master..spt_values WHERE TYPE='P'
.
January 21, 2011 at 11:54 pm
Here's my obvious, brute force answer. Sure seems slow though
DECLARE @Tally TABLE ( Number int)
DECLARE @ThisNum int
SET @ThisNum = 0
WHILE @ThisNum < 10000 BEGIN
INSERT INTO @Tally(Number) VALUES(@ThisNum)
SET @ThisNum = @ThisNum + 1
END
.
January 22, 2011 at 9:03 am
i haven't tried Azure yet, but why can't you create a permanent Tally table and use that?
Lowell
January 22, 2011 at 9:57 am
some methods are discussed here
January 22, 2011 at 10:27 am
Here is another way to create your tally table:
--==== cteTally
With e1 (n)
As ( --=== Create Ten 1's
Select 1 Union All Select 1 Union All
Select 1 Union All Select 1 Union All
Select 1 Union All Select 1 Union All
Select 1 Union All Select 1 Union All
Select 1 Union All Select 1)
, e2 (n) As (Select 1 From e1 a, e1 b)
, e3 (n) As (Select 1 From e2 a, e2 b)
, cteTally(n) As (Select row_number() over(Order By (Select n)) From e3)
Select *
From cteTally;
Jeffrey Williams
“We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”
― Charles R. Swindoll
How to post questions to get better answers faster
Managing Transaction Logs
January 22, 2011 at 4:53 pm
I guess a permanent tally makes the most sense. The cte tally table is nice for my situation, but I'll probably need it again before long. Thanks!
.
April 23, 2012 at 2:26 am
I'd recommend a tally table. Keep the computations to a minimum as this will result in more compute cycles which will impact on the cost of the instance over time.
:exclamation: "Be brave. Take risks. Nothing can substitute experience." :exclamation:
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply