Sunday, May 7, 2023

fun_GetLastDteOfTheMonth

 ALTER FUNCTION [pksf].[fun_GetLastDteOfTheMonth] 

(

@MM nvarchar(15),

@Year INT

)

RETURNS DATE

AS

BEGIN


DECLARE @LastDayOfTheMonth DATE, @MonthName nvarchar(100)

if       @MM='1' OR @MM='01'

set @MonthName='Jan'

else if  @MM='2' OR @MM='02'

set @MonthName='Feb'

else if  @MM='3' OR @MM='03'

set @MonthName='Mar'

else if  @MM='4' OR @MM='04'

set @MonthName='Apr'

else if  @MM='5' OR @MM='05'

set @MonthName='May'

else if  @MM='6' OR @MM='06'

set @MonthName='Jun'

else if  @MM='7' OR @MM='07'

set @MonthName='Jul'

else if  @MM='8' OR @MM='08'

set @MonthName='Aug'

else if  @MM='9' OR @MM='09'

set @MonthName='Sep'

else if  @MM='10'

set @MonthName='Oct'

else if  @MM='11'

set @MonthName='Nov'

else if  @MM='12'

set @MonthName='Dec'


SET @LastDayOfTheMonth=  CAST('01-'+@MonthName+'-'+ CAST(@Year as NVARCHAR(5)) AS DATE);

SET @LastDayOfTheMonth= EOMONTH(@LastDayOfTheMonth);

RETURN @LastDayOfTheMonth

END

No comments:

Post a Comment

Screen Record

 Windows Screen Record WindowsKey+ Alt + R Recording Starts.