C# Corner
Tech
News
Videos
Forums
Trainings
Books
Live
More
Interviews
Events
Jobs
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Convert Number to Roman Numerals in SQL Server
WhatsApp
Sandeep Mittal
Dec 22
2015
13.7
k
0
2
CREATE
FUNCTION
fnConvertIntToRoman(@i
INT
)
RETURNS
VARCHAR
(100)
AS
BEGIN
RETURN
Replicate(
'M'
, @i/1000)
+
REPLACE
(
REPLACE
(
REPLACE
(
Replicate(
'C'
, @i%1000/100),
Replicate(
'C'
, 9),
'CM'
),
Replicate(
'C'
, 5),
'D'
),
Replicate(
'C'
, 4),
'CD'
)
+
REPLACE
(
REPLACE
(
REPLACE
(
Replicate(
'X'
, @i%100 / 10),
Replicate(
'X'
, 9),
'XC'
),
Replicate(
'X'
, 5),
'L'
),
Replicate(
'X'
, 4),
'XL'
)
+
REPLACE
(
REPLACE
(
REPLACE
(
Replicate(
'I'
, @i%10),
Replicate(
'I'
, 9),
'IX'
),
Replicate(
'I'
, 5),
'V'
),
Replicate(
'I'
, 4),
'IV'
)
END
SQL Server
Convert Number to Roman Numerals
Up Next
Convert Number to Roman Numerals in SQL Server