create function get_format_num
(
@value int,
@header varchar(5),
@footer varchar(5)
)
returns varchar(36)
as
begin
declare @temp varchar(36)
declare @result varchar(36)
declare @i int
set @result = ''
if(isnumeric(@value) = 1)
begin
set @temp = reverse(cast(@value as varchar(36)))
set @i = 1
while(@i <= len(@temp))
begin
set @result = substring(@temp, @i, 1) + @result
if((@i % 3) = 0)
begin
set @result = ',' + @result
end
set @i = @i + 1
end
end
else
begin
set @result = '0'
end
if(substring(@result, 1, 1) = ',')
begin
set @result = substring(@result, 2, 36)
end
set @result = @header + @result + @footer
return @result
end
--실행방법
select BoardSample.dbo.get_format_num(E232, '', '원')
댓글 영역