You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ITSM/.svn/pristine/fb/fb2f8bc24a8c95a677031e732c5...

43 lines
2.4 KiB

USE [Vertragsverwaltung_20160404]
GO
/****** Object: UserDefinedFunction [dbo].[get_monatstabelle] Script Date: 02.12.2016 09:08:53 ******/
DROP FUNCTION [dbo].[get_monatstabelle]
GO
/****** Object: UserDefinedFunction [dbo].[get_monatstabelle] Script Date: 02.12.2016 09:08:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE FUNCTION [dbo].[get_monatstabelle](@from AS DATETIME, @to AS DATETIME)
RETURNS @Dates TABLE(start_date DATETIME, End_Date datetime)
AS
BEGIN
DECLARE @st DATETIME
DECLARE @ed DATETIME
WHILE @from < @to BEGIN
SELECT @st=DATEADD(MONTH, DATEDIFF(MONTH, 0, @from), 0)
SELECT @ed=DATEADD(DAY, -1, DATEADD(MONTH, DATEDIFF(MONTH, 0, @from) + 1, 0))
SET @ed=DATEADD(HOUR,23,@ed)
SET @ed=DATEADD(MINUTE,59,@ed)
SET @ed=DATEADD(SECOND,45,@ed)
INSERT @dates (start_date, end_date) VALUES(@st, @ed)
SET @from = DATEADD(MONTH, 1,@from)
end
RETURN
END
GO