Thinking outside the box

Patron Saint of Lost Yaks
posts - 203, comments - 734, trackbacks - 4

My Links

Advertisement

News

Archives

Post Categories

Ordinal your numbers

SELECT        number,
              CASE
                     WHEN number % 100 IN (11, 12, 13) THEN 'th'
                     WHEN number % 10 = 1 THEN 'st'
                     WHEN number % 10 = 2 THEN 'nd'
                     WHEN number % 10 = 3 THEN 'rd'
                     ELSE 'th'
              END AS Ordinal
FROM          master..spt_values
WHERE         type = 'p'
ORDER BY      number

Print | posted on Monday, October 27, 2008 8:29 AM | Filed Under [ SQL Server 2008 Algorithms SQL Server 2005 SQL Server 2000 ]

Feedback

Gravatar

# re: Ordinal your numbers

Well, that's handy! Thanks :)
10/27/2008 9:22 AM | Pass the Stripe
Comments have been closed on this topic.

Powered by:
Powered By Subtext Powered By ASP.NET