• CELKO (12/28/2012)


    Here is atrick weith a calendar table.

    CREATE TABLE Calendar

    (cal_date DATE NOT NULL PRIMARY KEY,

    julian_business_nbr INTEGER NOT NULL,

    ...);

    INSERT INTO Calendar

    VALUES ('2007-04-05', 42),

    ('2007-04-06', 43), -- good Friday

    ('2007-04-07', 43),

    ('2007-04-08', 43), -- Easter Sunday

    ('2007-04-09', 44),

    ('2007-04-10', 45); --Tuesday

    To compute the business days from Thursday of this week to next

    Tuesdays:

    SELECT (C2.julian_business_nbr - C1.julian_business_nbr)

    FROM Calendar AS C1, Calendar AS C2

    WHERE C1.cal_date = '2007-04-05',

    AND C2.cal_date = '2007-04-10';

    SQL Server 2005 doesn't support the DATE datatype. Also '2007-04-10' is DATEFORMAT dependent and could be interpreted as either 10th April or 4th October.

    ____________________________________________________

    Deja View - The strange feeling that somewhere, sometime you've optimised this query before

    How to get the best help on a forum

    http://www.sqlservercentral.com/articles/Best+Practices/61537