Fun Start End Date 2

  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Fun Start End Date 2 as PDF for free.

More details

  • Words: 146
  • Pages: 2
================== CASE 1 ================== CREATE FUNCTION [dbo].[fnc_Month_EndDate] ( @TargetDate DateTime, @AddMonths int ) RETURNS datetime AS BEGIN DECLARE @EndDate AS DateTime IF @AddMonths is NULL BEGIN set @AddMonths = 1 END else BEGIN set @AddMonths = @AddMonths +1 END IF @TargetDate IS NOT NULL BEGIN set @TargetDate = DateAdd( m, @AddMonths, @TargetDate) END BEGIN SELECT @EndDate = ( SELECT CAST(CAST(YEAR(@TargetDate) AS varchar(4)) + '-' + CAST(MONTH(@TargetDate) AS varchar(2)) + '-1' AS datetime) - 1 ) END RETURN @EndDate END

================== CASE 2 ================== CREATE FUNCTION [dbo].[fnc_Month_EndDate] ( @TargetDate DateTime, @AddMonths int ) RETURNS datetime AS BEGIN DECLARE @EndDate AS DateTime IF @AddMonths is NULL BEGIN set @AddMonths = 1 END

else BEGIN

set @AddMonths = @AddMonths +1

END BEGIN

SELECT @EndDate = ( SELECT DATEADD(d, -1, DATEADD(m, @AddMonths, CAST(CAST(YEAR(@TargetDate) AS varchar(4)) + '-' + CAST(MONTH(@TargetDate) AS varchar(2)) + '-1' AS datetime))) ) END RETURN @EndDate END

Related Documents

Fun Start End Date 2
June 2020 3
Start From The End
December 2019 8
Blog End Start Here
November 2019 7
Fun
May 2020 33
Fun
June 2020 27
Fun
November 2019 54