Ordinal Function - SQL Server

See also: Ordinal Function - C#

/*
select
     n
    ,result = dbo.Ordinal(n)
from
    dbo.GetCounterTable(50)
*/
create function dbo.Ordinal
    (
    @n int
    ) returns varchar(100) as begin

declare 
     @result varchar(100)
    ,@mod100 int
    ,@mod10  int

select
     @mod100    = @n % 100
    ,@mod10     = @n % 10
    ,@result    = convert(varchar(100), @n) + case
                    when @mod10 = 1 and @mod100 <> 11 then 'st'
                    when @mod10 = 2 and @mod100 <> 12 then 'nd'
                    when @mod10 = 3 and @mod100 <> 13 then 'rd'
                    else 'th'
                    end                      

return @result
end