2012年2月26日星期日

First Saturday Of The Year

Hi,
Is there a function that could return the first saturday of the year? If
not, is it possible to make use of existing functions to arrive at an
equivalent function to do this?
Regards,
EricEric,
I think the easiest way to do this is to build a calendar table that holds
the data, then you can simply join to this.
Mark Allison, SQL Server MVP
http://www.markallison.co.uk
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602m.html
"Eric" wrote:

> Hi,
> Is there a function that could return the first saturday of the year? If
> not, is it possible to make use of existing functions to arrive at an
> equivalent function to do this?
> Regards,
> Eric|||There is no bult-in function to do this, but as Mark says i would prefer
building up a calendar table (Temporay, you only need the at leat first 7
Days of the year) and get the specific Weekday (depending on your sttings
for the DATEFIRST setting.
Creating of a temptale with calandar entries can be found here.:
http://www.aspfaq.com/show.asp?id=2519
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Eric" <Eric@.discussions.microsoft.com> schrieb im Newsbeitrag
news:664EF52B-BDAE-4A61-810F-D1B3FD5F0B45@.microsoft.com...
> Hi,
> Is there a function that could return the first saturday of the year? If
> not, is it possible to make use of existing functions to arrive at an
> equivalent function to do this?
> Regards,
> Eric|||On Tue, 10 May 2005 18:32:01 -0700, Eric wrote:

>Hi,
>Is there a function that could return the first saturday of the year? If
>not, is it possible to make use of existing functions to arrive at an
>equivalent function to do this?
>Regards,
>Eric
Hi Eric,
Mark and Jens are correct: a calendar table is probably the best
solution for this. However, here's a function that will give you the
desired result for years 2000 and later (assuming that the date is ion a
column called TheDate):
SELECT DATEADD(day,
DATEDIFF (day,
'20000101',
CAST(DATEPART(year, TheDate) AS varchar)
+ '0107') / 7 * 7,
'20000101')
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

没有评论:

发表评论