How To Use:
SELECT dbo.UDF_GET_NEXT_WEEKDAY('20111223', 'SUNDAY')
This is the straight fwd and easy understanding way to retrieve the specified date..
We can similarly, get the specific date , which is preceded by a given date by changing line of code from (line no:13)
Select dayid, DATEADD(day, 1*dayid, @in_date) as possibledate
to
Select dayid, DATEADD(day, -1*dayid, @in_date) as possibledate