Showing posts with label public. Show all posts
Showing posts with label public. Show all posts

Thursday, March 22, 2012

Datetime/public holidays

I need to be able to determine whether a particular
datetime value is a public holiday (in the uk) or not and
I cannot find a documented way of deteriming this. Please
could you advise me whether there is a function or method
of determining this in SQL 2000 Enterprise Edition?
If there is not could you advise me a robust method of
providing this functionality for developers (I am a design
DBA who works with a number of different development teams
and it would seem appropriate for everyone to use the same
method)?
Many thanks,
DavePublic holiday dates are not always determined by a fixed logic. You should
build your own calendar table for this and populate it in advance with as
much data as you need.
CREATE TABLE Calendar (caldate DATETIME NOT NULL PRIMARY KEY, workingday
CHAR(1) NOT NULL CHECK (workingday IN ('Y','N')) DEFAULT 'Y')
INSERT INTO Calendar (caldate) VALUES ('20000101')
Populate it (this is 11 years worth of dates):
WHILE (SELECT MAX(caldate) FROM Calendar)<'20101231'
INSERT INTO Calendar (caldate)
SELECT DATEADD(D,DATEDIFF(D,'19991231',caldate),
(SELECT MAX(caldate) FROM Calendar))
FROM Calendar
Now update the non-working days:
UPDATE Calendar SET workingday = 'N'
WHERE DATENAME(DW,caldate) IN ('Saturday','Sunday')
A source I use for public holiday dates is: http://www.bank-holidays.com
--
David Portas
--
Please reply only to the newsgroup
--

Wednesday, March 7, 2012

DateTime calculation

I have two tables "publicholidays" and "RegDate". "publicholidays" simply
stores all the date of a public holidays in a particular year. RegDate
stores the date a user is being registered. I need to perform a calculation
that will calculate the number of days the user has been registered (exclude
publicholidays) and store the result in another field in RegDate table.
Put it simply:
TotalDays = TodayDate-DateRegistered-Number of PublicHolidays in between
Date registered and Todays Date
I need to implement this as store procedure. How do I perform such task ?
Thanks.SELECT DATEDIFF(d,DateRegistered, CURRENT_TIMESTAMP) - (SELECT COUNT *
FROM PublicHolidays
WHERE HolidayDate BETWEEN O.DataRegistered AND
CURRENT_TIMESTAMP) AS TotalDays
FROM YourTable O
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"quest" <anonymous@.microsoft.com> wrote in message
news:%23F2BLpzjFHA.1504@.TK2MSFTNGP10.phx.gbl...
>I have two tables "publicholidays" and "RegDate". "publicholidays" simply
> stores all the date of a public holidays in a particular year. RegDate
> stores the date a user is being registered. I need to perform a
> calculation
> that will calculate the number of days the user has been registered
> (exclude
> publicholidays) and store the result in another field in RegDate table.
> Put it simply:
> TotalDays = TodayDate-DateRegistered-Number of PublicHolidays in between
> Date registered and Todays Date
> I need to implement this as store procedure. How do I perform such task ?
> Thanks.
>|||Thanks. Is it possible to update a field in the same table ("O" in this
case) with the new calculated value ? I tried to do update but don't seem to
get the syntax right.
Thanks again.
"Roji. P. Thomas" <thomasroji@.gmail.com> wrote in message
news:uMHekw0jFHA.1416@.TK2MSFTNGP09.phx.gbl...
> SELECT DATEDIFF(d,DateRegistered, CURRENT_TIMESTAMP) - (SELECT COUNT *
> FROM PublicHolidays
> WHERE HolidayDate BETWEEN O.DataRegistered AND
> CURRENT_TIMESTAMP) AS TotalDays
> FROM YourTable O
>
> --
> Roji. P. Thomas
> Net Asset Management
> https://www.netassetmanagement.com
>
> "quest" <anonymous@.microsoft.com> wrote in message
> news:%23F2BLpzjFHA.1504@.TK2MSFTNGP10.phx.gbl...
?
>|||Try this
UPDATE YourTable
SET TotalDays = SELECT DATEDIFF(d,DateRegistered, CURRENT_TIMESTAMP) -
(SELECT COUNT *
FROM PublicHolidays
WHERE HolidayDate BETWEEN YourTable .DataRegistered AND
CURRENT_TIMESTAMP)
WHERE TotalDays IS NULL
Roji. P. Thomas
Net Asset Management
https://www.netassetmanagement.com
"quest" <anonymous@.microsoft.com> wrote in message
news:OFdHHkAkFHA.1416@.TK2MSFTNGP09.phx.gbl...
> Thanks. Is it possible to update a field in the same table ("O" in this
> case) with the new calculated value ? I tried to do update but don't seem
> to
> get the syntax right.
> Thanks again.
> "Roji. P. Thomas" <thomasroji@.gmail.com> wrote in message
> news:uMHekw0jFHA.1416@.TK2MSFTNGP09.phx.gbl...
> ?
>|||hi
just try this
UPDATE RegDate
SEt Regdate.Column = DATEDIFF(d,DateRegistered, CURRENT_TIMESTAMP) -
count(HolidayDate)
FROM RegDate
INNER JOIN PublicHolidays PH ON
HolidayDate BETWEEN O.DataRegistered AND CURRENT_TIMESTAMP
best Regards,
Chandra
http://groups.msn.com/SQLResource/
http://chanduas.blogspot.com/
---
*** Sent via Developersdex http://www.examnotes.net ***