Monday, March 26, 2012

Display date it differ year,month,week and date parameter

declare @no int,@date datetime=GETDATE()

declare @yy varchar(5)='2012',@mm varchar(2)='03',@week int=4,

@day varchar(2)='2'

select @date=@yy+'-'+@mm+'-'+'01'

select @no=DATEPART(WEEKDAY,@date)

if @no in(1,2)

select @date-(@no-2)

else

begin

select dateadd(ww,@week,@date)-(@no-@day)

end



No comments:

Post a Comment