Good Afternoon. I have two issues but I think that a solution to the first may do. I found some code to create a table I can (try to) use to identify work days when submitting an electronic holiday form.
Now I'm not saying that this is good code but it was the only starting place I could find. The main issue is trying to get the date in UK dd/mm/yyyy format
The first part was to create a table of numbers.
Then it was time to create the Calendar Table. Is it possible/should I be able to format the date at this stage?
I wondered whether I could format when I do this bit as the
doesn't work.
If I can get that bit right then the following could be called from our form
But as UK date format
Am I on the right track, or completely bonkers?
Many thanks.
Des
Now I'm not saying that this is good code but it was the only starting place I could find. The main issue is trying to get the date in UK dd/mm/yyyy format
The first part was to create a table of numbers.
Code:
-- Create the ‘Numbers’ table first
CREATE TABLE dbo.Numbers
(
Number INT IDENTITY(1,1) PRIMARY KEY CLUSTERED
)
WHILE COALESCE(SCOPE_IDENTITY(), 0) <= 11024
BEGIN
INSERT dbo.Numbers DEFAULT VALUES
END
Then it was time to create the Calendar Table. Is it possible/should I be able to format the date at this stage?
Code:
CREATE TABLE dbo.Calendar
(
Date SMALLDATETIME NOT NULL
PRIMARY KEY CLUSTERED,
isWeekday BIT,
isHoliday BIT,
Year SMALLINT,
FinancialYear SMALLINT,
Quarter TINYINT,
Month TINYINT,
Day TINYINT,
DayOfWeek TINYINT,
MonthName VARCHAR(9),
DayName VARCHAR(9),
Week TINYINT
)
GO
I wondered whether I could format when I do this bit as the
Code:
SET DATEFORMAT dd/mm/yyyy
Code:
INSERT Calendar(Date)
SELECT DATEADD(DAY, Number, '20100100')
FROM dbo.Numbers
WHERE Number <= 10957
-- 01/01/2040
SET DATEFORMAT dd/mm/yyyy
ORDER BY Number
If I can get that bit right then the following could be called from our form
Code:
--Number of Business days in Holiday selection
SELECT COUNT(date) AS 'Holidays' FROM dbo.Calendar
WHERE isWeekday = 1
AND isHoliday = 0
AND date >= '20100401' AND date <= '20100408'
But as UK date format
Code:
AND date >= '01042010' AND date <= '08042010'
Am I on the right track, or completely bonkers?
Many thanks.
Des