TABLE vALUED FUNCTION
USE [SystemTracker]
GO
/****** Object: UserDefinedFunction [dbo].[FN_LAST_WORKINGWEEK] Script Date: 17-11-2021 15:35:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*---------------------------------------------------------------------------------------------------------
FUNCTION NAME : FN_LAST_WORKINGWEEK
FUNCTION / PURPOSE : FUNCTION CALCULATES THE LAST WORKING WEEK OF THE USER
AUTHOR NAME : PANKAJ SAINI(2470)
CREATED DATE : 06-NOV-2017
REVISION HISTORY 1 : BY: PANKAJ SAINI -- ON: 06-NOV-2017 -- REVISION DETAILS: NEW FUNCTION CREATED.
-----------------------------------------------------------------------------------------------------------*/
ALTER FUNCTION [dbo].[FN_LAST_WORKINGWEEK]()
RETURNS @OUTPUTTBL TABLE (DATEVALSTART DATE, DATEVALEND DATE)
BEGIN
---------------------------------------------------------------------------------------------
-- DEFINED PARAMETER(S) | VARIABLE DATA TYPE | DEFAULT VAL -- COMMENTS
---------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
INSERT INTO @OUTPUTTBL (DATEVALSTART, DATEVALEND)
VALUES (CONVERT(DATE,DATEADD(dd, ((DATEDIFF(dd, '17530101', GETDATE()) / 7) * 7) - 7, '17530101')), --GIVES THE DATE OF MONDAY
CONVERT(DATE,DATEADD(dd, ((DATEDIFF(dd, '17530101', GETDATE()) / 7) * 7) - 1, '17530101'))); -- GIVES THE DATE OF SUNDAY
RETURN
END
Comments
Post a Comment