--:SetVar Function "AUX:ToRomanNumber.Ext"
if exists( select * from [sysobjects] (nolock) where [type] in ('FN','TF') and [name]=N'AUX:ToRomanNumber.Ext' )
   drop function [AUX:ToRomanNumber.Ext]
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:ToRomanNumber.Ext]( @Number int, @FormatUnsupportedValue bit=1 )
returns varchar(8)
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 varchar(8)
select @Display = [Display] from [AUX::Roman_numbers] (nolock) where [Number] = @Number

return ISNULL( @Display,
   case @FormatUnsupportedValue
      when 1 then '<'+CONVERT( varchar(8), @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'
*/
