The code sample is a sql function that computes the last day of a given month. The input is a month and the year. Other inputs are normally ignored.
The output to this code is the last day of the month given in the input.
Example: last of the July,2008 is Thursday, 31 2008.
CREATE FUNCTION [dbo].[fn_LastDayOfMonth] ( @pInputDate DATETIME ) RETURNS DATETIME BEGIN
DECLARE @vOutputDate DATETIME
SET @vOutputDate = CAST(YEAR(@pInputDate) AS VARCHAR(4)) + '/' + CAST(MONTH(@pInputDate) AS VARCHAR(2)) + '/01' SET @vOutputDate = DATEADD(DD, -1, DATEADD(M, 1, @vOutputDate))
RETURN @vOutputDate
END GO
|
No responses found. Be the first to respond and make money from revenue sharing program.
|