--:SetVar Function "AUX:DateValue.YMD"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:DateValue.YMD' )
   drop function [AUX:DateValue.YMD]
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:DateValue.YMD]( @Year int, @Month int, @Day int )
returns datetime2
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# MAKING DATE FROM YEAR, MONTH AND DAY:
#
# === Usage: ===
# dbo.[AUX:DateValue.YMD]( <Year>, <Month>, <Day> )
#
==================================================================================================*/

if @Year is null or @Month is null or @Day is null or
   not( @Month between 1 and 12 and @Day between 1 and 31 )
   return null

----------------------------------------------------------------------------------------------------

return DATETIME2FROMPARTS( @Year, @Month, @Day, 0, 0, 0, 0, 0 )
/*
return CONVERT( datetime2,
   dbo.[AUX:ToStringFS.Int]( @Year , 4 )+
   dbo.[AUX:ToStringFS.Int]( @Month, 2 )+
   dbo.[AUX:ToStringFS.Int]( @Day  , 2 ),
   $(num_ISODateFormatWithCentury_AUX) )
*/
/*================================================================================================*/
END
GO
/*
declare @Now datetime2
set @Now = GETDATE()
select dbo.[AUX:DateValue.YMD]( YEAR(@Now), MONTH(@Now), DAY(@Now) ) 'Current date'
select dbo.[AUX:DateValue.YMD]( 2017, 06, 14 ) 'Date value'
select dbo.[AUX:DateValue.YMD]( 2017, 06, 31 ) 'Incorrect date (June 31st)'
*/
