Create Function :
CREATE FUNCTION dbo.FindDate (@startDate datetime,@day int,@week int)
RETURNS datetime
BEGIN
DECLARE @answer datetime
DECLARE @dateResult datetime
DECLARE @noDayDateStart int
SET @noDayDateStart=DATEPART(dw, @startDate)-1
SET @dateResult =DATEADD(day,( 7*@week)-(7-@day)-@noDayDateStart,@startDate">7 * @week)-(7 - @day) - @noDayDateStart, @startDate)
SET @answer=@dateResult RETURN (@answer)
END
Test :
select dbo.FindDate ('2007-01-01',1,6)
Result :
No comments:
Post a Comment