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

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 Ordinal
FROM		master..spt_values
WHERE		Number BETWEEN 1 AND 255
		AND Name IS NULL
ORDER BY	Number

Rate

5 (2)

Share

Share

Rate

5 (2)