求用sql存储过程写将 小数(金额)转换成中文大写,急! 求用sql存储过程写将 小数(金额)转换成中文大写,急! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 -- --------调用示例-- declare @tt varchar(100)-- set @tt = dbo.F_Change(34546233.45)-- print @tt-- -- ---create function F_Change(@Cost decimal(28,2))returns varchar(100)asbegindeclare @l_cost varchar(16)declare @lstr varchar(13)declare @rstr1 char(1)declare @rstr2 char(1)declare @lenth intdeclare @return varchar(100)set @return = ''set @l_cost = convert(varchar(16),round(@Cost,2))set @lstr = left(@l_cost,len(@l_cost) - 3)----角set @rstr1 = left(right(@l_cost,2),1)----分set @rstr2 = right(@l_cost,1)set @lenth = len(@lstr)declare @tb table(lenth int identity(1,1), num char(1))while @lenth > 0begininsert into @tbvalues(right(@lstr,1))set @lstr = left(@lstr,len(@lstr) - 1)set @lenth = @lenth - 1enddeclare @tb1 table(minnum char(1),maxnum char(2))insert into @tb1select '0','零'union select '1','壹'union select '2','贰'union select '3','叁'union select '4','肆'union select '5','伍'unionselect '6','陆'unionselect '7','柒'unionselect '8','捌'unionselect '9','玖'declare @tb2 table(lenth int,unit char(2))insert into @tb2 select 1,'元'union select 2,'拾'union select 3,'佰'union select 4,'仟'union select 5,'万'unionselect 6,'拾'unionselect 7,'佰'unionselect 8,'仟'unionselect 9,'亿'unionselect 10,'拾'unionselect 11,'佰'unionselect 12,'仟'unionselect 13,'万'select @return = @return + (select tb1.maxnum from @tb1 tb1 where tb.num = tb1.minnum) + (select tb2.unit from @tb2 tb2 where tb.lenth = tb2.lenth)from @tb tborder by tb.lenth descset @return = @return + (select maxnum from @tb1 where minnum = @rstr1 ) + '角' + (select maxnum from @tb1 where minnum = @rstr2) + '分' + '整'return @return end sqlite3如何插入变量 [向happyflystone提问] 在函数中使用CTE遇到问题,来请教一下 请高手救场,急啊,现在就要用它取个数!!!!!!! SOS!!! 8152 错误如何处理 存储过程中的动态sql 再次请教:表名 可不可以,使用变量?以下代码,出错。 多级触发器问题 请问,如何用SQL语句求本周的记录?(表中有时间字段) 如何编写时间触发器 时间段查询的问题 原因
-- declare @tt varchar(100)
-- set @tt = dbo.F_Change(34546233.45)
-- print @tt
--
-- ---create function F_Change(@Cost decimal(28,2))
returns varchar(100)
as
begin
declare @l_cost varchar(16)
declare @lstr varchar(13)
declare @rstr1 char(1)
declare @rstr2 char(1)
declare @lenth int
declare @return varchar(100)
set @return = ''
set @l_cost = convert(varchar(16),round(@Cost,2))
set @lstr = left(@l_cost,len(@l_cost) - 3)
----角
set @rstr1 = left(right(@l_cost,2),1)
----分
set @rstr2 = right(@l_cost,1)
set @lenth = len(@lstr)
declare @tb table(lenth int identity(1,1), num char(1))
while @lenth > 0
begin
insert into @tb
values(right(@lstr,1))
set @lstr = left(@lstr,len(@lstr) - 1)
set @lenth = @lenth - 1
enddeclare @tb1 table(minnum char(1),maxnum char(2))
insert into @tb1
select '0','零'
union select '1','壹'
union select '2','贰'
union select '3','叁'
union select '4','肆'
union select '5','伍'
unionselect '6','陆'
unionselect '7','柒'
unionselect '8','捌'
unionselect '9','玖'declare @tb2 table(lenth int,unit char(2))
insert into @tb2
select 1,'元'
union select 2,'拾'
union select 3,'佰'
union select 4,'仟'
union select 5,'万'
unionselect 6,'拾'
unionselect 7,'佰'
unionselect 8,'仟'
unionselect 9,'亿'
unionselect 10,'拾'
unionselect 11,'佰'
unionselect 12,'仟'
unionselect 13,'万'select @return = @return
+ (select tb1.maxnum from @tb1 tb1 where tb.num = tb1.minnum)
+ (select tb2.unit from @tb2 tb2 where tb.lenth = tb2.lenth)
from @tb tb
order by tb.lenth descset @return = @return + (select maxnum from @tb1 where minnum = @rstr1 ) + '角'
+ (select maxnum from @tb1 where minnum = @rstr2) + '分' + '整'
return @return end