/****** Object:  UserDefinedFunction [dbo].[fnx_getFullMonth]    Script Date: 21.10.2016 11:01:05 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fnx_getFullMonth]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[fnx_getFullMonth]
GO
--SET ANSI_NULLS ON
--GO
--SET QUOTED_IDENTIFIER ON
--GO
--CREATE FUNCTION [dbo].[fnx_getFullMonth](@dateX [datetime], @dateY [datetime])
--RETURNS [int] WITH EXECUTE AS CALLER
--AS 
--BEGIN 
--	DECLARE @t table(dd int)
--	INSERT INTO @t(dd) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(15),(18),(21),(24),(26),(36),(48),(60),(72),(84),(96),(108),(120),(132),(144),(156),(168),(180),(192),(204)
--    DECLARE @y int, @lastYearDate datetime
--    set @lastYearDate = Cast(DATEPART(YEAR, @dateY) as varchar(4)) + '1231'
--    SET @y =DATEDIFF(month,@dateX,@dateY)
--	IF (@dateY < DATEADD(month, @y, @dateX)) SET @y = @y -1
--    if(@y <= 36 )
--    Begin
--		if(@y < 26 )
--    	begin
--			select top 1 @y=dd from @t where dd<=@y order by dd desc
--		end 
--		else
--			select @y = 36
--	end
--	else
--		begin
--			SET @y =DATEDIFF(month,@dateX,@lastYearDate)
--			select top 1 @y=dd from @t where dd<=@y order by dd desc
--		end
--	if (@y>204) select @y=204
--    RETURN @y
--END
