숫자를 문자로 나타내는 함수(숫자=>한글)
create function NumberToHanWords(@money as varchar(16))
returns varchar(35)
as
begin
declare @map varchar(35)
declare @nlen int
declare @mlen int
declare @npos int
declare @nchar char(1)
declare @str varchar(70)
declare @tmp varchar(2)
set @npos=0
set @map = '천백십조천백십억천백십만천백십 '
set @nlen=len(@money)
set @mlen=len(@map)
set @str=''
while @npos <=@nlen
begin
set @nchar = substring(@money,@npos+1,1)
select @tmp= case @nchar
when '1' then '일'
when '2' then '이'
when '3' then '삼'
when '4' then '사'
when '5' then '오'
when '6' then '육'
when '7' then '칠'
when '8' then '팔'
when '9' then '구'
when '0' then '영'
end
if @tmp <> '영'
begin
set @str= @str + @tmp + substring(@map, @mlen+1-@nlen + @npos +1 ,1)
end
else
begin
if ( @nlen - @npos - 1) % 4 = 0 and (right(@str,1) <>'조' and right(@str,1)<>'억' and right(@str,1)<>'만')
set @str= @str + substring(@map, @mlen+1-@nlen + @npos+1 ,1)
end
set @npos=@npos +1
end
return replace(@str,' ','')
end
[출처] 숫자를 문자로 나타내는 함수(숫자=>한글)|작성자 필립박