Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Working days calendar in T-SQL?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
pedestrian via SQLMonster.com  
View profile  
 More options Jun 19 2007, 9:22 am
Newsgroups: microsoft.public.sqlserver.programming
From: "pedestrian via SQLMonster.com" <u16758@uwe>
Date: Tue, 19 Jun 2007 13:22:22 GMT
Local: Tues, Jun 19 2007 9:22 am
Subject: Working days calendar in T-SQL?
My company working days is from Monday to Friday.
I would like to generate a result set which show all
consecutive working days (Monday to Friday excluding the
weekends) that is, for June 2007, it show me 1st, 4th, 5th,
6th, 8th, 11th etc... until 29th (last working day of June). Is
it possible to do this with T-SQL?

Thank you very much.

--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/2007...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Kuznetsov  
View profile  
 More options Jun 19 2007, 9:29 am
Newsgroups: microsoft.public.sqlserver.programming
From: Alex Kuznetsov <AK_TIREDOFS...@hotmail.COM>
Date: Tue, 19 Jun 2007 06:29:32 -0700
Local: Tues, Jun 19 2007 9:29 am
Subject: Re: Working days calendar in T-SQL?
On Jun 19, 8:22 am, "pedestrian via SQLMonster.com" <u16758@uwe>
wrote:

> My company working days is from Monday to Friday.
> I would like to generate a result set which show all
> consecutive working days (Monday to Friday excluding the
> weekends) that is, for June 2007, it show me 1st, 4th, 5th,
> 6th, 8th, 11th etc... until 29th (last working day of June). Is
> it possible to do this with T-SQL?

> Thank you very much.

> --
> Message posted via SQLMonster.comhttp://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/2007...

Yes, google up "calendar table".

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Uri Dimant  
View profile  
 More options Jun 19 2007, 9:27 am
Newsgroups: microsoft.public.sqlserver.programming
From: "Uri Dimant" <u...@iscar.co.il>
Date: Tue, 19 Jun 2007 16:27:47 +0300
Local: Tues, Jun 19 2007 9:27 am
Subject: Re: Working days calendar in T-SQL?
Hi
http://classicasp.aspfaq.com/date-time-routines-manipulation/how-do-i...

"pedestrian via SQLMonster.com" <u16758@uwe> wrote in message
news:73eef10337f0a@uwe...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Portas  
View profile  
 More options Jun 19 2007, 9:36 am
Newsgroups: microsoft.public.sqlserver.programming
From: David Portas <REMOVE_BEFORE_REPLYING_dpor...@acm.org>
Date: Tue, 19 Jun 2007 13:36:26 -0000
Local: Tues, Jun 19 2007 9:36 am
Subject: Re: Working days calendar in T-SQL?
On 19 Jun, 14:22, "pedestrian via SQLMonster.com" <u16758@uwe> wrote:

> My company working days is from Monday to Friday.

Is that always the case though? What about public holidays?

> I would like to generate a result set which show all
> consecutive working days (Monday to Friday excluding the
> weekends) that is, for June 2007, it show me 1st, 4th, 5th,
> 6th, 8th, 11th etc... until 29th (last working day of June). Is
> it possible to do this with T-SQL?

Use a calendar table:

SELECT dt
FROM Calendar
WHERE dt > '20070601'
 AND dt < '20070701'
 AND WorkingDay = 'Y';

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ML  
View profile  
 More options Jun 19 2007, 9:34 am
Newsgroups: microsoft.public.sqlserver.programming
From: ML <M...@discussions.microsoft.com>
Date: Tue, 19 Jun 2007 06:34:16 -0700
Local: Tues, Jun 19 2007 9:34 am
Subject: RE: Working days calendar in T-SQL?
Yes, consider using a calendar table. See this article for details:
http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using...

ML

---
http://milambda.blogspot.com/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pedestrian via SQLMonster.com  
View profile  
 More options Jun 20 2007, 8:47 am
Newsgroups: microsoft.public.sqlserver.programming
From: "pedestrian via SQLMonster.com" <u16758@uwe>
Date: Wed, 20 Jun 2007 12:47:10 GMT
Local: Wed, Jun 20 2007 8:47 am
Subject: Re: Working days calendar in T-SQL?
Hi, Uri, thanks for the link for useful information...

Uri Dimant wrote:
>Hi
>http://classicasp.aspfaq.com/date-time-routines-manipulation/how-do-i...

>> My company working days is from Monday to Friday.
>> I would like to generate a result set which show all
>[quoted text clipped - 4 lines]

>> Thank you very much.

--
Regards,
Pedestrian, Penang.

Message posted via http://www.sqlmonster.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pedestrian via SQLMonster.com  
View profile  
 More options Jun 20 2007, 8:46 am
Newsgroups: microsoft.public.sqlserver.programming
From: "pedestrian via SQLMonster.com" <u16758@uwe>
Date: Wed, 20 Jun 2007 12:46:50 GMT
Local: Wed, Jun 20 2007 8:46 am
Subject: Re: Working days calendar in T-SQL?
Hi, Uri, thanks for the link for useful information...

Uri Dimant wrote:
>Hi
>http://classicasp.aspfaq.com/date-time-routines-manipulation/how-do-i...

>> My company working days is from Monday to Friday.
>> I would like to generate a result set which show all
>[quoted text clipped - 4 lines]

>> Thank you very much.

--
Regards,
Pedestrian, Penang.

Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/2007...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pedestrian via SQLMonster.com  
View profile  
 More options Jun 20 2007, 8:48 am
Newsgroups: microsoft.public.sqlserver.programming
From: "pedestrian via SQLMonster.com" <u16758@uwe>
Date: Wed, 20 Jun 2007 12:48:11 GMT
Local: Wed, Jun 20 2007 8:48 am
Subject: RE: Working days calendar in T-SQL?
Thanks for the suggestion, ML.
Thank you Alex.

ML wrote:
>Yes, consider using a calendar table. See this article for details
>http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using...

>ML

>---
>http://milambda.blogspot.com/

--
Regards,
Pedestrian, Penang.

Message posted via http://www.sqlmonster.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pedestrian via SQLMonster.com  
View profile  
 More options Jun 20 2007, 8:54 am
Newsgroups: microsoft.public.sqlserver.programming
From: "pedestrian via SQLMonster.com" <u16758@uwe>
Date: Wed, 20 Jun 2007 12:54:42 GMT
Local: Wed, Jun 20 2007 8:54 am
Subject: Re: Working days calendar in T-SQL?
Ya.... I have to take care the holiday as well (which is stored in a table)
FYI, I have decided to create an Windows app that will be scheduled daily...

--
Regards,
Pedestrian, Penang.

Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/2007...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
--CELKO--  
View profile  
 More options Jun 20 2007, 12:27 pm
Newsgroups: microsoft.public.sqlserver.programming
From: --CELKO-- <jcelko...@earthlink.net>
Date: Wed, 20 Jun 2007 09:27:49 -0700
Local: Wed, Jun 20 2007 12:27 pm
Subject: Re: Working days calendar in T-SQL?
Build a calendar table with one column for the calendar data and other
columns to show whatever your business needs in the way of temporal
information.  Do not try to calculate holidays in SQL -- Easter alone
requires too much math.

CREATE TABLE Calendar
(cal_date DATE NOT NULL PRIMARY KEY,
 fiscal_year INTEGER NOT NULL,
 fiscal_month INTEGER NOT NULL,
 week_in_year INTEGER NOT NULL, -- SQL server is not ISO standard
 holiday_type INTEGER NOT NULL
         CHECK(holiday_type IN ( ..), --
 day_in_year INTEGER NOT NULL,
 julian_business_day INTEGER NOT NULL,
  ...);

The Julian business day is a good trick.  Number the days from
whenever your calendar starts and repeat a number for a weekend or
company holiday.

A calendar table for US Secular holidays can be built from the data at
this website, so you will get the three-day weekends:

http://www.smart.net/~mmontes/ushols.html

Time zones with fractional hour displacements
http://www.timeanddate.com/worldclock/city.html?n=246
http://www.timeanddate.com/worldclock/city.html?n=176
http://www.timeanddate.com/worldclock/city.html?n=5
http://www.timeanddate.com/worldclock/city.html?n=54

But the STRANGE ones are:
http://www.timeanddate.com/worldclock/city.html?n=63
http://www.timeanddate.com/worldclock/city.html?n=5


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
raibeart  
View profile  
 More options Jun 20 2007, 1:59 pm
Newsgroups: microsoft.public.sqlserver.programming
From: raibeart <raibe...@gmail.com>
Date: Wed, 20 Jun 2007 10:59:48 -0700
Local: Wed, Jun 20 2007 1:59 pm
Subject: Re: Working days calendar in T-SQL?
I use a concept that data warehouses use, a dimension table.

CREATE TABLE [dbo].[TIME_DIMENSION](
        [DATE_ID] [datetime] NOT NULL,
        [DAY_OF_WEEK] [varchar](50) NULL,
        [DAY_MONTH_NO] [int] NULL,
        [DAY_MONTH_TXT] [varchar](12) NULL,
        [DAY_YEAR_NO] [smallint] NULL,
        [DAY_OVERALL_NO] [int] NULL,
        [WEEK_YEAR_NO] [int] NULL,
        [WEEK_OVERALL_NO] [int] NULL,
        [MONTH_NO] [int] NULL,
        [MONTH_TXT] [varchar](15) NULL,
        [MONTH_OVERALL_NO] [int] NULL,
        [QUARTER_NO] [int] NULL,
        [FISCAL_PERIOD] [varchar](50) NULL,
        [HOLIDAY_FLG] [varchar](50) NULL,
        [WEEKDAY_FLG] [varchar](50) NULL,
        [LAST_DAY_IN_MONTH_FLG] [varchar](50) NULL,
        [YEAR_NO] [smallint] NULL,
        [CREATION_DATE] [datetime] NULL,
        [APP_LOGIN_CREATION] [varchar](50) NULL,
        [MODIFICATION_DATE] [datetime] NULL,
        [APP_LOGIN_MODIFICATION] [varchar](50) NULL,
 CONSTRAINT [TIME_DIMENSION_PK] PRIMARY KEY CLUSTERED
(
        [DATE_ID] ASC
)ON [PRIMARY]
) ON [PRIMARY]

Using this, there is essentially no math that needs to be done on
dates. You
simply join this tablewith any date column and you get all the
information about it.

I use an Access program to load the table initially and usually carry
100 to
150 years of data in it.

Robert

On Jun 19, 8:22 am, "pedestrian via SQLMonster.com" <u16758@uwe>
wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
pedestrian via SQLMonster.com  
View profile  
 More options Jun 21 2007, 9:37 am
Newsgroups: microsoft.public.sqlserver.programming
From: "pedestrian via SQLMonster.com" <u16758@uwe>
Date: Thu, 21 Jun 2007 13:37:43 GMT
Local: Thurs, Jun 21 2007 9:37 am
Subject: Re: Working days calendar in T-SQL?
To both CELKO and raibeart,
Thank you guy for the suggested solution...

--
Regards,
Pedestrian, Penang.

Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-programming/2007...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google