Step 1:- Create SQL Function
/****** Object: UserDefinedFunction [dbo].[getTotalDaysInMonth] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:
-- Create date: <25th July, 2009>
-- Description:
-- =============================================
CREATE FUNCTION [dbo].[getTotalDaysInMonth]
(
-- Add the parameters for the function here
@anydateofMonth DATETIME
)
RETURNS INT
AS
BEGIN
-- Declare the return variable here
DECLARE @totalDaysInMonth INT
-- Add the T-SQL statements to compute the return value here
DECLARE @givendate DATETIME
SET @givendate = @anydateofMonth
SET @givendate = STR(YEAR(@givendate)) + '-' + STR(MONTH(@givendate) + 1) + '-01'
SELECT @totalDaysInMonth = DATEPART(dd, DATEADD(DAY, -1, @givendate))
-- Return the result of the function
RETURN @totalDaysInMonth
END
Step 2:- Write SQL query
SELECT dbo.getLastBusinessDay(GETDATE()) AS TotalDaysInMonth
Comments
Post a Comment