"meg" <martorellg@hotmail.com> wrote in message
news:O0aIZ9z1EHA.1260@TK2MSFTNGP12.phx.gbl...
> "meg" wrote:
>
> I've created the calendar table and inserted my holidays, however I just
> don't know how to implement the
> query. If anyone has any experience with this I would greatly appreciate
> it!!
>
>
>
> Thanks,
>
> meg
>
>
>
>
> "Alejandro Mesa" <AlejandroMesa@discussions.microsoft.comwrote in message
>
> news:951B92C9-446C-48D8-91E0-3E14D3FFA47A@microsoft.com...
>
> See if this helps.
>
>
>
> Why should I consider using an auxiliary calendar table?
>
>
http://www.aspfaq.com/show.asp?id=2519 >
>
>
> AMB
>
>
>
> "meg" wrote:
>
>
>
> Hi, I am not sure how to implement a query where I have to find the
> difference between two dates but exclude
> weekends and company holidays. I did figure I would use datepart or
> datename somehow but I'm not sure how.
>
> I have a table that lists company holidays as well - but being a beginner
> at writing SQL I thought i'd ask
> here how to implement it. Below is sample data for testing. What I need
> to do is find the service requests
> (if any) that took longer than 48 hours to complete each fiscal month, if
> so, I have to exclude weekends and
> holidays from the 48 hours to find any service requests that took more
> than 48 "working" hours to complete.
>
>
>
> Thanks in advance, and let me know if you need more info.
>
>
>
> create table ServiceRequest(
>
> ServReqID int,
>
> CreatedDate datetime,
>
> CompletedDate datetime)
>
>
>
> create table Fiscal(
>
> FiscalMonth int,
>
> FiscalYear int,
>
> FiscalMonthStart datetime,
>
> FiscalMonthEnd datetime)
>
>
>
> create table Holiday(
>
> HolidayStart datetime,
>
> HolidayEnd datetime)
>
>
>
> Insert into Holiday
>
> Values ('2004-11-25 00:00:00.000','2004-11-26 23:59:00.000')
>
>
>
> Insert Into ServiceRequest
>
> Values (1, '2004-10-30 01:03:34.600','2004-10-30 01:40:06.600')
>
> Insert Into ServiceRequest
>
> Values (2, '2004-10-30 01:23:34.600','2004-10-30 01:43:06.307')
>
> Insert Into ServiceRequest
>
> Values (3, '2004-10-30 01:23:34.600','2004-10-30 01:46:07.930')
>
> Insert Into ServiceRequest
>
> Values (4, '2004-10-30 01:25:34.600','2004-11-01 02:46:07.590')
>
> Insert Into ServiceRequest
>
> Values (5, '2004-10-30 01:26:34.600','2004-11-02 01:46:08.497')
>
> Insert Into ServiceRequest
>
> Values (11, '2004-11-23 01:26:34.600','2004-11-29 01:46:08.497')
>
> Insert Into ServiceRequest
>
> Values (12, '2004-11-23 01:27:34.600','2004-11-29 00:46:08.497')
>
>
>
> Insert Into Fiscal
>
> Values (1,2005,'2004-10-30 00:00:00','2004-11-26 23:59:00')
>
>
>
> --Query to find SRs that took more than 48 hours to complete:
>
> select servicerequest.*, datediff(hh,createddate,completeddate)
>
> from fiscal join servicerequest on createddate between fiscalmonthstart
> and fiscalmonthend
>
> where fiscalmonth = 1 and fiscalyear = 2005 and
>
> datediff(hh,createddate,completeddate) 48
>
>