August 22, 2014 at 10:42 am
Comments posted to this topic are about the item Calculate gregorian easter sunday using a table valued function
September 3, 2014 at 4:26 am
Faster than the usual algorithm I use. Here's a little tidyup:
;WITH
Step1 AS( SELECT a = @year%19, b = FLOOR(1.0*@year/100), c = @year%100),
Step2 AS( SELECT a,b,c,d = FLOOR(1.0*b/4), e=b%4, f=FLOOR((8.0+b)/25) FROM Step1),
Step3 AS( SELECT a,b,c,d,e,g = FLOOR((1.0+ b- f)/3) FROM Step2),
Step4 AS( SELECT a,d,e,h = (19*a+b-d-g+15)%30, i= FLOOR(1.0*c/4), k= @year%4 FROM Step3),
Step5 AS( SELECT a,h,l = (32.0+2*e+2*i-h-k)%7 FROM Step4),
Step6 AS( SELECT h,l,m = FLOOR((1.0*a+11*h+22*l)/451) FROM Step5)
SELECT easterSunday = DATEFROMPARTS(@Year, FLOOR((1.0*h+l-7*m+114)/31), 1+(h+l-7*m+114)%31)
FROM Step6
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
September 6, 2014 at 7:59 am
Apologies if this is a silly question. But I seem to get the following error when running your script
Msg 243, Level 16, State 1, Procedure ufn_inltab_getGregorianEasterSunday, Line 4
Type DATE is not a defined system type.
September 6, 2014 at 1:58 pm
Hi!
Which server version of sql server are you using?
September 6, 2014 at 5:26 pm
SQL Server Express 2005 for testing
September 7, 2014 at 12:45 pm
Ok, try changing date to datetime in the function(s). It seems like date as a datatype didn't exist before sql server 2008.
2005:
http://msdn.microsoft.com/en-us/library/ms187752%28v=sql.90%29.aspx
2008:
http://msdn.microsoft.com/en-us/library/ms187752%28v=sql.100%29.aspx
Best regards,
Robin
September 8, 2014 at 12:41 pm
Fantastic. that sorted it.
Thanks so much for looking into this.
May 21, 2015 at 1:32 pm
Cute. Not sure I'll ever use it though.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply