Number weeks of work

  • thank for reply.

    I tried your last code but I have error in variable "@CountOfEmp":

    DECLARE @CountOfEmp INT = (SELECT COUNT(*) FROM [dbo].[names]);

    WITH GroupsOfWeeks AS (

    SELECT *

    --,n=1+(((ROW_NUMBER() OVER (ORDER BY Dates)-1)/5) % 5)

    ,n=1+(DATEPART(week, Dates)-1)%@CountOfEmp

    FROM [dbo].[dates]

    )

    SELECT Dates, Holidays, DayDates, DayHolidays, names

    FROM GroupsOfWeeks

    INNER JOIN [dbo].[names] ON n = id

    WHERE Dates NOT IN (

    SELECT Holidays

    FROM [dbo].[dates]

    WHERE Holidays IS NOT NULL)

    ORDER BY Dates

    [Err] 42000 - [SQL Server] Must declare the scalar variable "@CountOfEmp"

    My version of sql server is

    Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86)

    Jun 17 2011 00:57:23

    Copyright (c) Microsoft Corporation

    Express Edition on Windows NT 5.1 <X86> (Build 2600: Service Pack 3)

    dwain.c (12/25/2012)

    One question though. Why didn't you include 2013-01-01 as the first row in your dates table?

    Because a public holiday.

    Thank you

  • cms9651 (12/26/2012)


    thank for reply.

    I tried your last code but I have error in variable "@CountOfEmp"

    <snip>

    I'm not quite sure why but try the full code at the bottom of this post without change. Did you perhaps put a "GO" directive after the DECLARE?

    cms9651 (12/26/2012)


    dwain.c (12/25/2012)

    One question though. Why didn't you include 2013-01-01 as the first row in your dates table?

    Because a public holiday.

    Thank you

    That explains it. I thought the other holidays were included. So it means that my WHERE clause is not required.

    -- ----------------------------

    -- Table structure for [dbo].[tbl_dates]

    -- ----------------------------

    GO

    CREATE TABLE [dbo].[tbl_dates] (

    [Dates] date NOT NULL ,

    [Holidays] date NULL ,

    [DayDates] varchar(20) NULL ,

    [DayHolidays] varchar(20) NULL

    )

    GO

    -- ----------------------------

    -- Records of tbl_dates

    -- ----------------------------

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-02', N'2013-01-01', N'mercoledì', N'martedì');

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-03', N'2013-04-01', N'giovedì', N'lunedì');

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-04', N'2013-04-25', N'venerdì', N'giovedì');

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-07', N'2013-05-01', N'lunedì', N'mercoledì');

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-08', N'2013-08-15', N'martedì', N'giovedì');

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-09', N'2013-11-01', N'mercoledì', N'venerdì');

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-10', N'2013-12-25', N'giovedì', N'mercoledì');

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-11', N'2013-12-26', N'venerdì', N'giovedì');

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-14', N'2013-12-31', N'lunedì', N'martedì');

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-15', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-16', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-17', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-18', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-21', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-22', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-23', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-24', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-25', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-28', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-29', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-30', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-01-31', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-01', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-04', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-05', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-06', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-07', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-08', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-11', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-12', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-13', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-14', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-15', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-18', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-19', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-20', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-21', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-22', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-25', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-26', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-27', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-02-28', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-01', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-04', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-05', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-06', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-07', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-08', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-11', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-12', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-13', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-14', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-15', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-18', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-19', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-20', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-21', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-22', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-25', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-26', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-27', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-28', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-03-29', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-02', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-03', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-04', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-05', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-08', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-09', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-10', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-11', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-12', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-15', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-16', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-17', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-18', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-19', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-22', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-23', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-24', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-26', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-29', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-04-30', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-02', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-03', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-06', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-07', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-08', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-09', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-10', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-13', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-14', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-15', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-16', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-17', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-20', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-21', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-22', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-23', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-24', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-27', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-28', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-29', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-30', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-05-31', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-03', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-04', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-05', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-06', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-07', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-10', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-11', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-12', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-13', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-14', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-17', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-18', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-19', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-20', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-21', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-24', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-25', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-26', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-27', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-06-28', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-01', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-02', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-03', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-04', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-05', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-08', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-09', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-10', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-11', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-12', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-15', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-16', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-17', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-18', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-19', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-22', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-23', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-24', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-25', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-26', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-29', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-30', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-07-31', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-01', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-02', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-05', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-06', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-07', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-08', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-09', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-12', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-13', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-14', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-16', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-19', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-20', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-21', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-22', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-23', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-26', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-27', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-28', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-29', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-08-30', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-02', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-03', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-04', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-05', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-06', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-09', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-10', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-11', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-12', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-13', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-16', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-17', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-18', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-19', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-20', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-23', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-24', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-25', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-26', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-27', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-09-30', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-01', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-02', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-03', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-04', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-07', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-08', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-09', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-10', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-11', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-14', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-15', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-16', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-17', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-18', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-21', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-22', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-23', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-24', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-25', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-28', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-29', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-30', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-10-31', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-04', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-05', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-06', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-07', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-08', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-11', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-12', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-13', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-14', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-15', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-18', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-19', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-20', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-21', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-22', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-25', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-26', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-27', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-28', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-11-29', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-02', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-03', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-04', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-05', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-06', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-09', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-10', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-11', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-12', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-13', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-16', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-17', null, N'martedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-18', null, N'mercoledì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-19', null, N'giovedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-20', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-23', null, N'lunedì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-27', null, N'venerdì', null);

    GO

    INSERT INTO [dbo].[tbl_dates] ([Dates], [Holidays], [DayDates], [DayHolidays]) VALUES (N'2013-12-30', null, N'lunedì', null);

    GO

    -- ----------------------------

    -- Indexes structure for table tbl_dates

    -- ----------------------------

    -- ----------------------------

    -- Primary Key structure for table [dbo].[tbl_dates]

    -- ----------------------------

    ALTER TABLE [dbo].[tbl_dates] ADD PRIMARY KEY ([Dates])

    GO

    -- ----------------------------

    -- Table structure for [dbo].[tbl_names]

    -- ----------------------------

    GO

    CREATE TABLE [dbo].[tbl_names] (

    [names] varchar(50) NULL ,

    [id] int NOT NULL IDENTITY(1,1)

    )

    GO

    DBCC CHECKIDENT(N'[dbo].[tbl_names]', RESEED, 5)

    GO

    -- ----------------------------

    -- Records of tbl_names

    -- ----------------------------

    SET IDENTITY_INSERT [dbo].[tbl_names] ON

    GO

    INSERT INTO [dbo].[tbl_names] ([names], [id]) VALUES (N'George', N'1');

    GO

    INSERT INTO [dbo].[tbl_names] ([names], [id]) VALUES (N'Laura', N'2');

    GO

    INSERT INTO [dbo].[tbl_names] ([names], [id]) VALUES (N'Martin', N'3');

    GO

    INSERT INTO [dbo].[tbl_names] ([names], [id]) VALUES (N'Arnold', N'4');

    GO

    INSERT INTO [dbo].[tbl_names] ([names], [id]) VALUES (N'Betty', N'5');

    GO

    SET IDENTITY_INSERT [dbo].[tbl_names] OFF

    GO

    -- ----------------------------

    -- Indexes structure for table tbl_names

    -- ----------------------------

    -- ----------------------------

    -- Primary Key structure for table [dbo].[tbl_names]

    -- ----------------------------

    ALTER TABLE [dbo].[tbl_names] ADD PRIMARY KEY ([id])

    GO

    DECLARE @CountOfEmp INT = (SELECT COUNT(*) FROM [dbo].[tbl_names]);

    WITH GroupsOfWeeks AS (

    SELECT *

    --,n=1+(((ROW_NUMBER() OVER (ORDER BY Dates)-1)/5) % 5)

    ,n=1+(DATEPART(week, Dates)-1)%@CountOfEmp

    FROM [dbo].[tbl_dates]

    )

    SELECT Dates, Holidays, DayDates, DayHolidays, names

    FROM GroupsOfWeeks

    INNER JOIN [dbo].[tbl_names] ON n = id

    --WHERE Dates NOT IN (

    -- SELECT Holidays

    -- FROM [dbo].[tbl_dates]

    -- WHERE Holidays IS NOT NULL)

    ORDER BY Dates

    DROP TABLE [dbo].[tbl_names]

    DROP TABLE [dbo].[tbl_dates]


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • dwain.c (12/26/2012)


    I'm not quite sure why but try the full code at the bottom of this post without change.

    I tried your full code, I have the same error:

    [Err] 42000 - [SQL Server] Must declare the scalar variable "@CountOfEmp"

    Did you perhaps put a "GO" directive after the DECLARE?

    Not Sir

  • cms9651 (12/26/2012)


    dwain.c (12/26/2012)


    I'm not quite sure why but try the full code at the bottom of this post without change.

    I tried your full code, I have the same error:

    [Err] 42000 - [SQL Server] Must declare the scalar variable "@CountOfEmp"

    Did you perhaps put a "GO" directive after the DECLARE?

    Not Sir

    Strange. That code runs fine for me. So try this - remove the DECLARE and change:

    ,n=1+(DATEPART(week, Dates)-1)%@CountOfEmp

    To this:

    ,n=1+(DATEPART(week, Dates)-1)%5


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • dwain.c (12/26/2012)


    cms9651 (12/26/2012)


    dwain.c (12/26/2012)


    I'm not quite sure why but try the full code at the bottom of this post without change.

    I tried your full code, I have the same error:

    [Err] 42000 - [SQL Server] Must declare the scalar variable "@CountOfEmp"

    Did you perhaps put a "GO" directive after the DECLARE?

    Not Sir

    Strange. That code runs fine for me. So try this - remove the DECLARE and change:

    ,n=1+(DATEPART(week, Dates)-1)%@CountOfEmp

    To this:

    ,n=1+(DATEPART(week, Dates)-1)%5

    thank you now working and I have the correct output:

    WITH GroupsOfWeeks AS (

    SELECT *

    --,n=1+(((ROW_NUMBER() OVER (ORDER BY Dates)-1)/5) % 5)

    --,n=1+(DATEPART(week, Dates)-1)%@CountOfEmp

    ,n=1+(DATEPART(week, Dates)-1)%5

    FROM [dbo].[tbl_dates]

    )

    SELECT Dates, DayDates, [names]

    FROM GroupsOfWeeks

    INNER JOIN [dbo].[tbl_names] ON n = id

    --WHERE Dates NOT IN (

    -- SELECT Holidays

    -- FROM [dbo].[tbl_dates]

    -- WHERE Holidays IS NOT NULL)

    ORDER BY Dates

    DatesDayDatesnames

    2013-01-02mercoledìGeorge

    2013-01-03giovedìGeorge

    2013-01-04venerdìGeorge

    2013-01-07lunedìLaura

    2013-01-08martedìLaura

    2013-01-09mercoledìLaura

    2013-01-10giovedìLaura

    2013-01-11venerdìLaura

    2013-01-14lunedìMartin

    2013-01-15martedìMartin

    2013-01-16mercoledìMartin

    2013-01-17giovedìMartin

    2013-01-18venerdìMartin

    2013-01-21lunedìArnold

    2013-01-22martedìArnold

    2013-01-23mercoledìArnold

    2013-01-24giovedìArnold

    2013-01-25venerdìArnold

    2013-01-28lunedìBetty

    2013-01-29martedìBetty

    2013-01-30mercoledìBetty

    2013-01-31giovedìBetty

    2013-02-01venerdìBetty

    thanks a lot !

    🙂

  • You're welcome.

    BTW. You do see what I was trying to do with @CountOfEmp right?

    In case you have more than 5 employees in the table, the right argument of the modulo operator (%) must reflect the correct employee count for the query to work.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • dwain.c (12/26/2012)


    You're welcome.

    BTW. You do see what I was trying to do with @CountOfEmp right?

    Yes sir, I see and I love it!

    In case you have more than 5 employees in the table, the right argument of the modulo operator (%) must reflect the correct employee count for the query to work.

    Of course.

    I really appreciate your help

    Happy new year!

Viewing 7 posts - 16 through 21 (of 21 total)

You must be logged in to reply to this topic. Login to reply