I just created a function which does what you need
alter FUNCTION fnBala (
@Year varchar(20),
@Month varchar(20),
@Day2Find varchar(20),
@nth int
)
RETURNS date
AS
BEGIN
-- select dbo.fnBala ('2012','JAN','MON',1)
Declare @StartDate date =convert(date,'1/'+@Month+'/'+@Year)
Declare @FirstDateOfMonth date
Declare @Factor int=-1
if @Day2Find='SUN' set @Factor=6
else if @Day2Find='SAT' set @Factor=5
else if @Day2Find='MON' set @Factor=0
else if @Day2Find='TUE' set @Factor=1
else if @Day2Find='WED' set @Factor=2
else if @Day2Find='THU' set @Factor=3
else if @Day2Find='FRI' set @Factor=4
if ( @Factor - DATEDIFF(DD,0,@StartDate)%7) <0
set @FirstDateOfMonth=dateadd("d",( @Factor - DATEDIFF(DD,0,@StartDate)%7)+7,@StartDate)
else
set @FirstDateOfMonth=dateadd("d",( @Factor - DATEDIFF(DD,0,@StartDate)%7),@StartDate)
return dateadd("d",7*(@nth-1),@FirstDateOfMonth)
END
Fist time when you are creating the function
alter FUNCTION fnBala
needs to be repalced by
create FUNCTION fnBala
1 If you want to find if feb2010 month 1st sunday is what date?
select dbo.fnBala ('2010','FEB','SUN',1)
2. If you want to find feb2011 3rd sunday is what date?
select dbo.fnBala ('2011','FEB','SUN',3)
I just tested this on SQL server 2008 and it works for me and not suree what is your SQL server version and please let me know if you get any error message along with the SQL server version
Hope this helps