--:SetVar Function "AUX:YMComparison.ByDate"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:YMComparison.ByDate' )
   drop function [AUX:YMComparison.ByDate]
GO
/* Translated by $SQLTRANS utility (SQL-file technology). Method author: Sergei Y.Kitáev.
** Script translation date-time: 2022-11-27 00:29:27.24 (stamp of SQL-file generation). */
create function [AUX:YMComparison.ByDate]( @Date_1 datetime2,
                               @Year_2 int, @Month_2 int=null )
returns int
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# COMPARISON OF TWO YEAR-MONTHS (WITH FIRST ARGUMENT OF “DATETIME” TYPE):
#
# Comparison result
# :   -1 —— 1st year-month is lesser than 2nd year-month;
# :    1 —— 1st year-month is greater than 2nd year-month;
# :    0 —— 1st year-month is equal to 2nd year-month;
# : null —— correlation is undetermined (null arg(s) or incorrect YM2)
#
# === Usage: ===
# dbo.[AUX:YMComparison.ByDate]( <Date-1>, <Year-2>, <Month-2> )
# dbo.[AUX:YMComparison.ByDate]( <Date-1>, <Year-2>, null )
#
==================================================================================================*/

if @Date_1 is null
   return null

return
   dbo.[AUX:YMComparison](
      YEAR(@Date_1), MONTH(@Date_1),
      @Year_2, @Month_2 )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:YMComparison.ByDate]( CONVERT(datetime2,'11/01/2015',101), 2015,11   ) 'YM-comparison result'
select dbo.[AUX:YMComparison.ByDate]( CONVERT(datetime2,'11/01/2015',101), 2015,10   ) 'YM-comparison result'
select dbo.[AUX:YMComparison.ByDate]( CONVERT(datetime2,'11/01/2015',101), 2015,12   ) 'YM-comparison result'
select dbo.[AUX:YMComparison.ByDate]( CONVERT(datetime2,'11/01/2015',101), 2015,null ) 'YM-comparison result'
select dbo.[AUX:YMComparison.ByDate]( CONVERT(datetime2,'11/01/2015',101), 2016,null ) 'YM-comparison result'
*/
