:SetVar Function "AUX:ToRomanNumber.Ext"
:r $(DropFunctionScript_AUX)
create function [$(Function)]( @Number int, @FormatUnsupportedValue bit=1 )
returns $(dt_RomanNumber_AUX)
BEGIN
/*==================================================================================================
# SQLAUX scripting library | Author: Sergei Y.Kitáev
----------------------------------------------------------------------------------------------------
#
# CONVERSION TO ROMAN NUMBER INSCRIPTION (WORKING VALUES: 1..100):
# (EXTENDED VERSION)
#
# === Usage: ===
# dbo.[AUX:ToRomanNumber.Ext]( <Number>, 0 )
# dbo.[AUX:ToRomanNumber.Ext]( <Number>, 1 )
#
==================================================================================================*/

if @FormatUnsupportedValue is null
   return null

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

declare @Display $(dt_RomanNumber_AUX)
select @Display = [Display] from [AUX::Roman_numbers] (nolock) where [Number] = @Number

return ISNULL( @Display,
   case @FormatUnsupportedValue
      when 1 then '<'+CONVERT( $(dt_RomanNumber_AUX), @Number )+'>'
      else null
   end )

/*================================================================================================*/
END
GO
/*
select dbo.[AUX:ToRomanNumber.Ext]( 0, 0 ) 'Roman number inscription for 0'
select dbo.[AUX:ToRomanNumber.Ext]( 0, 1 ) 'Roman number inscription for 0'
select dbo.[AUX:ToRomanNumber.Ext]( 4, 0 ) 'Roman number inscription for 4'
select dbo.[AUX:ToRomanNumber.Ext]( 15, 0 ) 'Roman number inscription for 15'
select dbo.[AUX:ToRomanNumber.Ext]( 100, 0 ) 'Roman number inscription for 100'
select dbo.[AUX:ToRomanNumber.Ext]( 101, 0 ) 'Roman number inscription for 101'
select dbo.[AUX:ToRomanNumber.Ext]( 101, 1 ) 'Roman number inscription for 101'
*/
