• Working great for 1,2,3 & 4th occurances, but if i pass in 5 for april 2010, i am getting the wrong date

    For example:

    SELECT dbo.getNthOccuranceOfWeekDay(YEAR(GETDATE()), MONTH(GETDATE()), 1, 5)

    Resulting in:

    2010-04-18 00:00:00.000

    Should be:

    2010-04-25 00:00:00.000 (because the 25th is the last occurance of sunday in April.

    Please advise.

    Edit: my above issue occurs with Mitesh Oswal's version only, the version from Rajneesh Kumardev does not suffer from this problem.

    Knock Knock, Who's There?, sp underscore, sp underscore who?
    spid1, spid2, spid3....