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


Tally Table Uses - Part I


Tally Table Uses - Part I

Author
Message
alen teplitsky
alen teplitsky
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11052 Visits: 4674
thx

i've read tally table articles here for the last few years and never thought i had a use for them. last 6 months i've been building a performance data warehouse but haven't done too much in getting use out of the data. going to build a tally table into it just to divide the data into weeks, months, etc to see if we can find trends later on
Steve Jones
Steve Jones
SSC Guru
SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)

Group: Administrators
Points: 221119 Visits: 19614
I've always had to build a separate table and maintain it. Something like

Period  Date
1 1/1/2000
1 1/2/2000
...
1 1/28/2000
2 1/29/2000
...



Follow me on Twitter: @way0utwest
Forum Etiquette: How to post data/code on a forum to get the best help
My Blog: www.voiceofthedba.com
Carolyn Stern
Carolyn Stern
SSC Veteran
SSC Veteran (225 reputation)SSC Veteran (225 reputation)SSC Veteran (225 reputation)SSC Veteran (225 reputation)SSC Veteran (225 reputation)SSC Veteran (225 reputation)SSC Veteran (225 reputation)SSC Veteran (225 reputation)

Group: General Forum Members
Points: 225 Visits: 69
Hi - Actually this isn't a very specific use of a tally table for one customer.

This is called the "Retail Calendar" and is used by pretty much every retail business including the one I work for. We have retail stores and we have a large factory.

You can google it and look it up.

I don't know if this person is on the retail calendar or if he just has a weird fiscal set up.

I have been using a similar tally table for several years. One of the things I include is whether that particular date is a "working factory day". That doesn't mean to exclude sat/sun/holiday. As we approach the holidays we often have sat/sun where the factory works and ships product. So after the fact we add a Y if the factory worked that day.
Sioban Krzywicki
Sioban Krzywicki
SSCertifiable
SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)

Group: General Forum Members
Points: 7117 Visits: 8102
Carolyn Stern (8/2/2010)
Hi - Actually this isn't a very specific use of a tally table for one customer.

This is called the "Retail Calendar" and is used by pretty much every retail business including the one I work for. We have retail stores and we have a large factory.

You can google it and look it up.

I don't know if this person is on the retail calendar or if he just has a weird fiscal set up.

I have been using a similar tally table for several years. One of the things I include is whether that particular date is a "working factory day". That doesn't mean to exclude sat/sun/holiday. As we approach the holidays we often have sat/sun where the factory works and ships product. So after the fact we add a Y if the factory worked that day.



Interesting, this is for a retail company, but I don't know if they are on a standard "retail calendar" or if they've made up their own that is just very similar. Does the standard one have the "correction" of an additional week that I entered?

Thanks for the information!

--------------------------------------
When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
--------------------------------------
It’s unpleasantly like being drunk.
What’s so unpleasant about being drunk?
You ask a glass of water. -- Douglas Adams
alen teplitsky
alen teplitsky
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11052 Visits: 4674
wish i just had a tally table

bought my wife an iPhone 4 just now and needed to know which days were week 30 of 2010 since that when her phone was manufactured. rumor is that the latest iphones have a matte coating on the antennal to avoid the death grip issue

Apple uses the week of manufacture as part of the serial number in all of their products
Sioban Krzywicki
Sioban Krzywicki
SSCertifiable
SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)

Group: General Forum Members
Points: 7117 Visits: 8102
alen teplitsky (8/2/2010)
wish i just had a tally table

bought my wife an iPhone 4 just now and needed to know which days were week 30 of 2010 since that when her phone was manufactured. rumor is that the latest iphones have a matte coating on the antennal to avoid the death grip issue

Apple uses the week of manufacture as part of the serial number in all of their products


I didn't know that about Apple.
Has she been having a problem with the phone? My fiance and I have iPhone 4s and we haven't had the problem. Plus, they are giving out free cases through an app for the phone.

--------------------------------------
When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
--------------------------------------
It’s unpleasantly like being drunk.
What’s so unpleasant about being drunk?
You ask a glass of water. -- Douglas Adams
john.campbell-1020429
john.campbell-1020429
Old Hand
Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)Old Hand (392 reputation)

Group: General Forum Members
Points: 392 Visits: 336
I have also used Jeff's code as a jumping off point to do date tally tables. Julian date conversions were what started me down this road. I usually use the days int value as the pk_for the table with
select cast(getdate() as int)
Language conversions and other wierd stuff can then be stored in the date table that I usually put in master.
John.
alen teplitsky
alen teplitsky
SSChampion
SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)SSChampion (11K reputation)

Group: General Forum Members
Points: 11052 Visits: 4674
Stefan Krzywicki (8/2/2010)
alen teplitsky (8/2/2010)
wish i just had a tally table

bought my wife an iPhone 4 just now and needed to know which days were week 30 of 2010 since that when her phone was manufactured. rumor is that the latest iphones have a matte coating on the antennal to avoid the death grip issue

Apple uses the week of manufacture as part of the serial number in all of their products


I didn't know that about Apple.
Has she been having a problem with the phone? My fiance and I have iPhone 4s and we haven't had the problem. Plus, they are giving out free cases through an app for the phone.


new iphone 4 is still in the box. just bought it from the NYC Upper West Side store 90 minutes ago. called and they had a lot of stock.

the death grip issue is only if you're in a low signal level zone. wife has had a 3G since 2/2009 and i had a 3GS since June of 2009. i knew the 5 bars most of the time was a bunch of BS and something apple put in the software. i also had something similar to the death grip with my 3GS a few times when using it on wifi. while SJ was giving his we're as bad as everyone else speech i replicated the issue on my Blackberry Curve on one half of the room i was in. the other half the room has a better signal

and in my opinion apple knew about it before the release. i though it was strange that they were hyping the bumpers as well and i thought that touching the antenna may cause issues. or maybe it would increase the signal since it would allow the user to be the antenna as well.

a lot of the hysteria is just internet hype. there are PR/marketing firms who hire people to do nothing but post on forums and youtube and whatever. apple is not perfect but i'm 99% sure one of their competitors created the hysteria via one of these new advertising firms

for the serial number i've known about it for a while. when the 27" iMac's came out last year with the yellow screens everyone on MacRumors was tracking the week of manufacture to see if the issue was fixed. few weeks ago Gizmodo ran an article that Genius Bar iPhone 4 replacements were different than launch ones. which is why i wish i had a tally table and instead had to google "week 30 2010" to check the dates
Everett Travis
Everett Travis
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 42
A CTE could also be used to generate a tally table in memory. This can come in handy if you don't have access to create a table or wish to create a table for short-term use.


WITH Tally
AS
(
SELECT
TOP 20000
ROW_NUMBER() OVER (ORDER BY SC1.name) AS N
FROM
master.dbo.syscolumns AS SC1
CROSS JOIN master.dbo.syscolumns AS SC2
)


Sioban Krzywicki
Sioban Krzywicki
SSCertifiable
SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)SSCertifiable (7.1K reputation)

Group: General Forum Members
Points: 7117 Visits: 8102
Everett T (8/2/2010)
A CTE could also be used to generate a tally table in memory. This can come in handy if you don't have access to create a table or don't wish to create a table for short-term use.


WITH Tally
AS
(
SELECT
TOP 20000
ROW_NUMBER() OVER (ORDER BY SC1.name) AS N
FROM
master.dbo.syscolumns AS SC1
CROSS JOIN master.dbo.syscolumns AS SC2
)



Sure, or you could just use a temp table or table variable. Still no need to use a CTE to do it either. Heck, if you really wanted to leave no long-term footprint, just make both your tally table and your date table temp tables and drop them when you're done. Or make them both table variables, which is harder to use if you want to keep adding bits and testing them as you add them, but still works.

--------------------------------------
When you encounter a problem, if the solution isn't readily evident go back to the start and check your assumptions.
--------------------------------------
It’s unpleasantly like being drunk.
What’s so unpleasant about being drunk?
You ask a glass of water. -- Douglas Adams
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