USE [FastMoneyPro_Remit]
GO
/****** Object:  UserDefinedFunction [dbo].[GetOrdinal]    Script Date: 8/22/2023 9:19:36 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER FUNCTION [dbo].[GetOrdinal] (@number INT)
RETURNS NVARCHAR(20)
AS
BEGIN
    DECLARE @result NVARCHAR(20);
    SET @result = CASE
        WHEN @number % 100 IN (11, 12, 13) THEN CAST(@number AS NVARCHAR(20)) + 'th'
        WHEN @number % 10 = 1 THEN CAST(@number AS NVARCHAR(20)) + 'st'
        WHEN @number % 10 = 2 THEN CAST(@number AS NVARCHAR(20)) + 'nd'
        WHEN @number % 10 = 3 THEN CAST(@number AS NVARCHAR(20)) + 'rd'
        ELSE CAST(@number AS NVARCHAR(20)) + 'th'
    END
    SET @result = UPPER(@result)

    RETURN @result
END

