create function [dbo].[F_SB_GetConFloatStr]
(
@iNum float = null, /*Money*/
@iInt int = null /*소수점 자리수*/
)
returns varchar(50)
as
begin
declare @wRtnStr varchar(50)
declare @wInputStr varchar(50)
declare @wInputStr1 varchar(50)
declare @wInputStr2 varchar(50)
declare @wPos int
declare @wPos1 int
declare @wZero varchar(10)
set @wInputStr = rtrim(ltrim(str(@iNum,50,10)))
select @wPos = charindex('.',@wInputStr,1)
select @wInputStr1 = convert(varchar,convert(money,left(@wInputStr,@wPos-1)),1)
select @wPos1 = charindex('.',@wInputStr1,1)
select @wInputStr1 = left(@wInputStr1,@wPos1)
select @wInputStr2 = substring(@wInputStr,@wPos+1,@iInt)
select @wPos = len(@wInputStr2)- @iInt
while @wPos > 0
begin
select @wInputStr2 = @wInputStr2 + '0'
select @wPos1 = @wPos1 - 1
end
if isnull(@iInt,0) = 0
begin
select @wRtnStr = substring(@wInputStr1,1,len(@wInputStr1)-1)
end
else
begin
select @wRtnStr = rtrim(ltrim(@wInputStr1)) + rtrim(ltrim(@wInputStr2))
end
set @wZero = '0.'
while @iInt > 0
begin
select @wZero = @wZero + '0'
select @iInt = @iInt - 1
end
return(isnull(@wRtnStr,@wZero))
end
ex)
select dbo.F_SB_GetConFloatStr(12345678.9878,4)
== 12,345,678.9878
SQLServer : Convert/Cast 의 새로운 발견 (0) | 2010.11.26 |
---|---|
SQL Server 2008 T-SQL (0) | 2010.11.18 |
저장 프로시저 성능추적 (0) | 2010.10.15 |
MS SQL 에서 XML (0) | 2010.09.16 |
MS SQL 에서 CURSOR 사용하기3 (0) | 2010.09.16 |