## Calculate gregorian easter sunday using a table valued function

 Author Message robin.langell Forum Newbie Group: General Forum Members Points: 2 Visits: 57 Comments posted to this topic are about the item Calculate gregorian easter sunday using a table valued function ChrisM@Work SSChampion Group: General Forum Members Points: 10236 Visits: 19221 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` “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail ShawFor 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 ModenExploring Recursive CTEs by Example Dwain Camps terry.home SSC Rookie Group: General Forum Members Points: 38 Visits: 188 Apologies if this is a silly question. But I seem to get the following error when running your scriptMsg 243, Level 16, State 1, Procedure ufn_inltab_getGregorianEasterSunday, Line 4Type DATE is not a defined system type. robin.langell Forum Newbie Group: General Forum Members Points: 2 Visits: 57 Hi!Which server version of sql server are you using? terry.home SSC Rookie Group: General Forum Members Points: 38 Visits: 188 SQL Server Express 2005 for testing robin.langell Forum Newbie Group: General Forum Members Points: 2 Visits: 57 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.aspx2008:http://msdn.microsoft.com/en-us/library/ms187752%28v=sql.100%29.aspxBest regards,Robin terry.home SSC Rookie Group: General Forum Members Points: 38 Visits: 188 Fantastic. that sorted it. Thanks so much for looking into this. Iwas Bornready SSCrazy Eights Group: General Forum Members Points: 9816 Visits: 885 Cute. Not sure I'll ever use it though.