Technical Article

Fetching Ordinal number text

,

Interested in getting the ordinal number as text?
You know, 1st, 32nd and so on?

Have a look at this script.

peso@developerworkshop.net

SELECTNumber,
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 Ordinal
FROMmaster..spt_values
WHERENumber BETWEEN 1 AND 255
AND Name IS NULL
ORDER BYNumber

Rate

5 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (2)

You rated this post out of 5. Change rating