SQL Server’da Sayıları Roma Rakamına Çeviren Fonksiyon
Herkese merhaba,
Bu kısımda SQL Server’da sayıları roma rakamına çeviren fonksiyon kodları olacak.
create function fn_get_roman_numerals(@inputstring as int,@isupper bit) returns varchar(128) as begin declare @returnstring varchar(100), @sub varchar(100), @number bigint, @position int, @mod bigint set @returnstring = '' --set roman symbols orders set @sub = 'IVXLCDM' if @inputstring=0 begin set @returnstring = '' end else begin select @position = 1, @number = abs(@inputstring) while(@position<=5) begin set @mod = @number % 10 set @number = @number / 10 select @returnstring = case when @mod in (0,1,2,3) then replicate(substring(@sub,@position,1),@mod) + @returnstring when @mod in (4) then substring(@sub,@position,2) + @returnstring when @mod in (5,6,7,8) then substring(@sub,@position+1,1) + replicate(substring(@sub,@position,1),@mod-5) + @returnstring when @mod in (9) then substring(@sub,@position,1) + substring(@sub,@position+2,1) + @returnstring end set @position = @position + 2 end set @returnstring = replicate('M',@number) + @returnstring if @inputstring < 0 set @returnstring = '-' + @returnstring end if @isupper = 0 set @returnstring = lower(@returnstring) return @returnstring end go --Çalıştırılması select dbo.fn_get_roman_numerals(1000,1) select dbo.fn_get_roman_numerals(133,0)