4个回答
展开全部
Create Procedure AtoC
@ChangeMoney Money
as
Set Nocount ON
Declare @String1 char(20)
Declare @String2 char(30)
Declare @String4 Varchar(100)
Declare @String3 Varchar(100) –从原A值中取出的值
Declare @i int –循环变量
Declare @J Int –A的值乘以100的字符串长度
Declare @Ch1 Varchar(100) –数字的汉语读法
Declare @Ch2 Varchar(100) –数字位的汉字读法
Declare @Zero Int –用来计算连续有几个零
Declare @ReturnValue VarChar(100)
Select @ReturnValue = ”
Select @String1 = ‘零壹贰叁肆伍陆柒捌玖’
Select @String2 = ‘万仟佰拾亿仟佰拾万仟佰拾元角分’
Select @String4 = Cast(@ChangeMoney*100 as int)
select @J=len(cast((@ChangeMoney*100) as int))
Select @String2=Right(@String2,@J)
Select @i = 1
while @i<= @j Begin
Select @String3 = Substring(@String4,@i,1)
if @String3<>‘0′ Begin
Select @Ch1 = Substring(@String1, Cast(@String3 as Int) + 1, 1)
Select @Ch2 = Substring(@String2, @i, 1)
Select @Zero = 0 –表示本位不为零
end
else Begin
If (@Zero = 0) Or (@i = @J – 9) Or (@i = @J – 5) Or (@i = @J – 1)
Select @Ch1 = ‘零’
Else
Select @Ch1 = ”
Select @Zero = @Zero + 1 –表示本位为0
–如果转换的数值需要扩大,那么需改动以下表达式 I 的值。
Select Ch2 = ”
If @i = @J – 10 Begin
Select @Ch2 = ‘亿’
Select @Zero = 0
end
If @i = @J – 6 Begin
Select @Ch2 = ‘万’
Select @Zero = 0
end
if @i = @J – 2 Begin
Select @Ch2 = ‘元’
Select @Zero = 0
end
If @i = @J
Select @Ch2 = ‘整’
end
Select @ReturnValue = @ReturnValue + @Ch1 + @Ch2
select @i = @i+1
end
–最后将多余的零去掉
If CharIndex(‘仟仟’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘仟仟’, ‘仟’)
If CharIndex(‘佰佰’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘佰佰’, ‘佰’)
If CharIndex(‘零元’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零元’, ‘元’)
If CharIndex(‘零万’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零万’, ‘万’)
If CharIndex(‘零亿’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零亿’, ‘亿’)
If CharIndex(‘零整’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零整’, ‘整’)
If CharIndex(‘零佰’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零佰’, ‘零’)
If CharIndex(‘零仟’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零仟’, ‘零’)
If CharIndex(‘元元’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘元元’, ‘元’)
Select @ReturnValue
GO
@ChangeMoney Money
as
Set Nocount ON
Declare @String1 char(20)
Declare @String2 char(30)
Declare @String4 Varchar(100)
Declare @String3 Varchar(100) –从原A值中取出的值
Declare @i int –循环变量
Declare @J Int –A的值乘以100的字符串长度
Declare @Ch1 Varchar(100) –数字的汉语读法
Declare @Ch2 Varchar(100) –数字位的汉字读法
Declare @Zero Int –用来计算连续有几个零
Declare @ReturnValue VarChar(100)
Select @ReturnValue = ”
Select @String1 = ‘零壹贰叁肆伍陆柒捌玖’
Select @String2 = ‘万仟佰拾亿仟佰拾万仟佰拾元角分’
Select @String4 = Cast(@ChangeMoney*100 as int)
select @J=len(cast((@ChangeMoney*100) as int))
Select @String2=Right(@String2,@J)
Select @i = 1
while @i<= @j Begin
Select @String3 = Substring(@String4,@i,1)
if @String3<>‘0′ Begin
Select @Ch1 = Substring(@String1, Cast(@String3 as Int) + 1, 1)
Select @Ch2 = Substring(@String2, @i, 1)
Select @Zero = 0 –表示本位不为零
end
else Begin
If (@Zero = 0) Or (@i = @J – 9) Or (@i = @J – 5) Or (@i = @J – 1)
Select @Ch1 = ‘零’
Else
Select @Ch1 = ”
Select @Zero = @Zero + 1 –表示本位为0
–如果转换的数值需要扩大,那么需改动以下表达式 I 的值。
Select Ch2 = ”
If @i = @J – 10 Begin
Select @Ch2 = ‘亿’
Select @Zero = 0
end
If @i = @J – 6 Begin
Select @Ch2 = ‘万’
Select @Zero = 0
end
if @i = @J – 2 Begin
Select @Ch2 = ‘元’
Select @Zero = 0
end
If @i = @J
Select @Ch2 = ‘整’
end
Select @ReturnValue = @ReturnValue + @Ch1 + @Ch2
select @i = @i+1
end
–最后将多余的零去掉
If CharIndex(‘仟仟’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘仟仟’, ‘仟’)
If CharIndex(‘佰佰’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘佰佰’, ‘佰’)
If CharIndex(‘零元’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零元’, ‘元’)
If CharIndex(‘零万’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零万’, ‘万’)
If CharIndex(‘零亿’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零亿’, ‘亿’)
If CharIndex(‘零整’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零整’, ‘整’)
If CharIndex(‘零佰’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零佰’, ‘零’)
If CharIndex(‘零仟’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘零仟’, ‘零’)
If CharIndex(‘元元’,@ReturnValue) <> 0
Select @ReturnValue = Replace(@ReturnValue, ‘元元’, ‘元’)
Select @ReturnValue
GO
展开全部
Create
Procedure
AtoC
@ChangeMoney
Money
as
Set
Nocount
ON
Declare
@String1
char(20)
Declare
@String2
char(30)
Declare
@String4
Varchar(100)
Declare
@String3
Varchar(100)
–从原A值中取出的值
Declare
@i
int
–循环变量
Declare
@J
Int
–A的值乘以100的字符串长度
Declare
@Ch1
Varchar(100)
–数字的汉语读法
Declare
@Ch2
Varchar(100)
–数字位的汉字读法
Declare
@Zero
Int
–用来计算连续有几个零
Declare
@ReturnValue
VarChar(100)
Select
@ReturnValue
=
”
Select
@String1
=
‘零壹贰叁肆伍陆柒捌玖’
Select
@String2
=
‘万仟佰拾亿仟佰拾万仟佰拾元角分’
Select
@String4
=
Cast(@ChangeMoney*100
as
int)
select
@J=len(cast((@ChangeMoney*100)
as
int))
Select
@String2=Right(@String2,@J)
Select
@i
=
1
while
@i<=
@j
Begin
Select
@String3
=
Substring(@String4,@i,1)
if
@String3<>‘0′
Begin
Select
@Ch1
=
Substring(@String1,
Cast(@String3
as
Int)
+
1,
1)
Select
@Ch2
=
Substring(@String2,
@i,
1)
Select
@Zero
=
0
–表示本位不为零
end
else
Begin
If
(@Zero
=
0)
Or
(@i
=
@J
–
9)
Or
(@i
=
@J
–
5)
Or
(@i
=
@J
–
1)
Select
@Ch1
=
‘零’
Else
Select
@Ch1
=
”
Select
@Zero
=
@Zero
+
1
–表示本位为0
–如果转换的数值需要扩大,那么需改动以下表达式
I
的值。
Select
Ch2
=
”
If
@i
=
@J
–
10
Begin
Select
@Ch2
=
‘亿’
Select
@Zero
=
0
end
If
@i
=
@J
–
6
Begin
Select
@Ch2
=
‘万’
Select
@Zero
=
0
end
if
@i
=
@J
–
2
Begin
Select
@Ch2
=
‘元’
Select
@Zero
=
0
end
If
@i
=
@J
Select
@Ch2
=
‘整’
end
Select
@ReturnValue
=
@ReturnValue
+
@Ch1
+
@Ch2
select
@i
=
@i+1
end
–最后将多余的零去掉
If
CharIndex(‘仟仟’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘仟仟’,
‘仟’)
If
CharIndex(‘佰佰’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘佰佰’,
‘佰’)
If
CharIndex(‘零元’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零元’,
‘元’)
If
CharIndex(‘零万’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零万’,
‘万’)
If
CharIndex(‘零亿’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零亿’,
‘亿’)
If
CharIndex(‘零整’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零整’,
‘整’)
If
CharIndex(‘零佰’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零佰’,
‘零’)
If
CharIndex(‘零仟’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零仟’,
‘零’)
If
CharIndex(‘元元’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘元元’,
‘元’)
Select
@ReturnValue
GO
Procedure
AtoC
@ChangeMoney
Money
as
Set
Nocount
ON
Declare
@String1
char(20)
Declare
@String2
char(30)
Declare
@String4
Varchar(100)
Declare
@String3
Varchar(100)
–从原A值中取出的值
Declare
@i
int
–循环变量
Declare
@J
Int
–A的值乘以100的字符串长度
Declare
@Ch1
Varchar(100)
–数字的汉语读法
Declare
@Ch2
Varchar(100)
–数字位的汉字读法
Declare
@Zero
Int
–用来计算连续有几个零
Declare
@ReturnValue
VarChar(100)
Select
@ReturnValue
=
”
Select
@String1
=
‘零壹贰叁肆伍陆柒捌玖’
Select
@String2
=
‘万仟佰拾亿仟佰拾万仟佰拾元角分’
Select
@String4
=
Cast(@ChangeMoney*100
as
int)
select
@J=len(cast((@ChangeMoney*100)
as
int))
Select
@String2=Right(@String2,@J)
Select
@i
=
1
while
@i<=
@j
Begin
Select
@String3
=
Substring(@String4,@i,1)
if
@String3<>‘0′
Begin
Select
@Ch1
=
Substring(@String1,
Cast(@String3
as
Int)
+
1,
1)
Select
@Ch2
=
Substring(@String2,
@i,
1)
Select
@Zero
=
0
–表示本位不为零
end
else
Begin
If
(@Zero
=
0)
Or
(@i
=
@J
–
9)
Or
(@i
=
@J
–
5)
Or
(@i
=
@J
–
1)
Select
@Ch1
=
‘零’
Else
Select
@Ch1
=
”
Select
@Zero
=
@Zero
+
1
–表示本位为0
–如果转换的数值需要扩大,那么需改动以下表达式
I
的值。
Select
Ch2
=
”
If
@i
=
@J
–
10
Begin
Select
@Ch2
=
‘亿’
Select
@Zero
=
0
end
If
@i
=
@J
–
6
Begin
Select
@Ch2
=
‘万’
Select
@Zero
=
0
end
if
@i
=
@J
–
2
Begin
Select
@Ch2
=
‘元’
Select
@Zero
=
0
end
If
@i
=
@J
Select
@Ch2
=
‘整’
end
Select
@ReturnValue
=
@ReturnValue
+
@Ch1
+
@Ch2
select
@i
=
@i+1
end
–最后将多余的零去掉
If
CharIndex(‘仟仟’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘仟仟’,
‘仟’)
If
CharIndex(‘佰佰’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘佰佰’,
‘佰’)
If
CharIndex(‘零元’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零元’,
‘元’)
If
CharIndex(‘零万’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零万’,
‘万’)
If
CharIndex(‘零亿’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零亿’,
‘亿’)
If
CharIndex(‘零整’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零整’,
‘整’)
If
CharIndex(‘零佰’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零佰’,
‘零’)
If
CharIndex(‘零仟’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘零仟’,
‘零’)
If
CharIndex(‘元元’,@ReturnValue)
<>
0
Select
@ReturnValue
=
Replace(@ReturnValue,
‘元元’,
‘元’)
Select
@ReturnValue
GO
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <--->
-- Create date: <2008-3-4>
-- Description: <将阿拉伯数字转换成汉字大写>
-- =============================================
ALTER function [dbo].[ConvertNumberToChinese](@inputId money)
RETURNS Nvarchar(4000) AS
BEGIN
declare @rV Nvarchar(4000)
declare @tmpstr Nvarchar(4000),@M Nvarchar(4000),@K Nvarchar(4000),@I numeric(38,2),
@J int,@lastJ int,@LastV Nvarchar(10),@LastF Nvarchar(10),@LastE Nvarchar(10),@LastVE Nvarchar(10)
set @I=@inputId
set @K=N''
if @I<0
begin
set @I=0-@I
set @K=N'负'
end
if @I=0 return N'零元整'
select @tmpstr=N'零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿拾佰仟',@M=cast(cast(@I*100 as bigint) as varchar(800)),@J=len(@M),@LastVE=N''
while @J>=1
begin
set @LastF=substring(@tmpstr, cast(substring(@m,len(@M)-@j+1,1) as bigint)+1,1)
set @LastE=substring(@tmpstr,10+@J,1)
if @LastF<>N'零'
begin
if @LastV=N'零'
if (@lastJ>=7 and @j<7) or (@lastJ>=11 and @j<11 ) or (@lastJ>=3 and @j<=2)
if @J<=2 and @lastJ<=3
set @K=@K+@LastVE+@LastF+@LastE
else
set @K=@K+@LastVE+@LastV+@LastF+@LastE
else
set @K=@K+@LastV+@LastF+@LastE
else
set @K=@K+@LastF+@LastE
select @lastJ=@j,@LastVE=N''
end
else
begin
if @LastVE=N'' and @lastJ>11 set @LastVE=N'亿'
if @LastVE=N'' and @lastJ>7 and @lastJ<10 set @LastVE=N'万'
if @LastVE=N'' and @lastJ>3 and @lastJ<6 set @LastVE=N'元'
if @LastVE=N'' and @lastJ>2 set @LastVE=N'零'
if @LastV<>N'零' set @lastJ=@j
end
set @LastV=@LastF
set @J=@J-1
end
if @lastJ>=6 set @K=@K+@LastVE
if @lastJ>=3 set @K=@K+N'元'
if @lastJ>1 or (@lastJ=1 and @LastV=N'零') set @K=@K+N'整'
set @rv=@K
return @rv
END
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ll_newboy/archive/2008/03/04/2146714.aspx
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: <--->
-- Create date: <2008-3-4>
-- Description: <将阿拉伯数字转换成汉字大写>
-- =============================================
ALTER function [dbo].[ConvertNumberToChinese](@inputId money)
RETURNS Nvarchar(4000) AS
BEGIN
declare @rV Nvarchar(4000)
declare @tmpstr Nvarchar(4000),@M Nvarchar(4000),@K Nvarchar(4000),@I numeric(38,2),
@J int,@lastJ int,@LastV Nvarchar(10),@LastF Nvarchar(10),@LastE Nvarchar(10),@LastVE Nvarchar(10)
set @I=@inputId
set @K=N''
if @I<0
begin
set @I=0-@I
set @K=N'负'
end
if @I=0 return N'零元整'
select @tmpstr=N'零壹贰叁肆伍陆柒捌玖分角元拾佰仟万拾佰仟亿拾佰仟',@M=cast(cast(@I*100 as bigint) as varchar(800)),@J=len(@M),@LastVE=N''
while @J>=1
begin
set @LastF=substring(@tmpstr, cast(substring(@m,len(@M)-@j+1,1) as bigint)+1,1)
set @LastE=substring(@tmpstr,10+@J,1)
if @LastF<>N'零'
begin
if @LastV=N'零'
if (@lastJ>=7 and @j<7) or (@lastJ>=11 and @j<11 ) or (@lastJ>=3 and @j<=2)
if @J<=2 and @lastJ<=3
set @K=@K+@LastVE+@LastF+@LastE
else
set @K=@K+@LastVE+@LastV+@LastF+@LastE
else
set @K=@K+@LastV+@LastF+@LastE
else
set @K=@K+@LastF+@LastE
select @lastJ=@j,@LastVE=N''
end
else
begin
if @LastVE=N'' and @lastJ>11 set @LastVE=N'亿'
if @LastVE=N'' and @lastJ>7 and @lastJ<10 set @LastVE=N'万'
if @LastVE=N'' and @lastJ>3 and @lastJ<6 set @LastVE=N'元'
if @LastVE=N'' and @lastJ>2 set @LastVE=N'零'
if @LastV<>N'零' set @lastJ=@j
end
set @LastV=@LastF
set @J=@J-1
end
if @lastJ>=6 set @K=@K+@LastVE
if @lastJ>=3 set @K=@K+N'元'
if @lastJ>1 or (@lastJ=1 and @LastV=N'零') set @K=@K+N'整'
set @rv=@K
return @rv
END
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ll_newboy/archive/2008/03/04/2146714.aspx
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select case IP_IP when '0' then '男' else '女' end,case IP_IP when '0' then '12' else '34' end from IP_Binding
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询