-- Collection of code snippets by Arne Vajhøj 
-- (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
CREATE ASSEMBLY nu FROM 'C:\NU.dll' WITH PERMISSION_SET = SAFE
GO

CREATE FUNCTION XFORMAT(@n INTEGER, @fmt NVARCHAR(50))
RETURNS NVARCHAR(50)
AS
EXTERNAL NAME nu.[E.NumberUtil].XFormat
GO

SELECT DBO.XFORMAT(123, '0')
GO
SELECT DBO.XFORMAT(123, '#')
GO
SELECT DBO.XFORMAT(123, '00000')
GO
SELECT DBO.XFORMAT(123, '#####')
GO

DROP FUNCTION XFORMAT
GO
DROP ASSEMBLY nu
GO
