转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 数据库 >> SyBase >> 正文
献个丑,写了个小写转大写的sp ,0.1 版本继续测试中         ★★★★

献个丑,写了个小写转大写的sp ,0.1 版本继续测试中

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1488 更新时间:2009/4/22 23:09:37

--更换的最新版本 
--另外临时表可以考虑改成永久表

if exists (select * from sysobjects where name = 'sp_convertmoney' and type = 'P')
  drop procedure sp_convertmoney  
go
create procedure sp_convertmoney  
  @convmoney numeric(12,2)  
as   
begin  
set nocount on   
create table #tmp0 --大小写对比表  
(id        numeric(2,0) identity not null,  
 digital   char(1)      not null,  
 dx        char(2)      not null,  
   
insert into #tmp0(digital,dx) values('1','壹')  
insert into  #tmp0(digital,dx) values('2','贰')  
insert into  #tmp0(digital,dx) values('3','叁')  
insert into  #tmp0(digital,dx) values('4','肆')  
insert into  #tmp0(digital,dx) values('5','伍')  
insert into  #tmp0(digital,dx) values('6','陆')  
insert into  #tmp0(digital,dx) values('7','柒')  
insert into  #tmp0(digital,dx) values('8','捌')  
insert into  #tmp0(digital,dx) values('9','玖')  
insert into  #tmp0(digital,dx) values('0','零')  

create table #tmp1(  
     id   numeric(2,0) identity not null,  --序列号码  
     pos1   integer      not null,           --数据位置号    
     num    char(1)      null    ,           --待转换的数据     
     unit   char(2)      null     ,    --单位  
     dx     char(2)    null           --保存该数据的大写  
)  
insert into  #tmp1 (pos1,unit) values(-2,'分')  
insert into  #tmp1 (pos1,unit) values(-1,'角')  
insert into  #tmp1 (pos1,unit) values(0,' ')  
insert into  #tmp1 (pos1,unit) values(1,'元')  
insert into  #tmp1 (pos1,unit) values(2,'拾')  
insert into  #tmp1 (pos1,unit) values(3,'佰')  
insert into  #tmp1 (pos1,unit) values(4,'仟')  
insert into  #tmp1 (pos1,unit) values(5,'万')  
insert into  #tmp1 (pos1,unit) values(6,'拾')  
insert into  #tmp1 (pos1,unit) values(7,'佰')  
insert into  #tmp1 (pos1,unit) values(8,'仟')  
insert into  #tmp1 (pos1,unit) values(9,'亿')  
insert into  #tmp1 (pos1,unit) values(10,'拾')  
insert into  #tmp1 (pos1,unit) values(11,'佰')  
insert into #tmp1 (pos1,unit) values(12,'仟')  

declare @strmoney      varchar(15), --声明字符型变量保存输入金额  
        @revsstrmoney  varchar(15), --逆序字符  
      @len0    smallint,       --全部数字长度  
        @adig    char(1),             --存放单个数字   
       @i integer   
select @i= 1  
select   @convmoney  = convert(numeric(12,2),@convmoney)  --强制转换为 numeric(12,2)格式  
select   @strmoney   = convert(varchar(15),@convmoney) 
select  @revsstrmoney  = reverse(@strmoney)      
select @len0  = datalength(@strmoney)
while   @i<=@len0  
begin  
  select @adig = substring(@revsstrmoney,@i,1)  
  update #tmp1 set num = @adig where id = @i  
  select @i = @i+1  
end  

update #tmp1 set dx = b.dx from #tmp1 a , #tmp0  b   
  where a.num = b.digital  
/*
select id,num,dx,unit,dx+unit as dx_unit  from #tmp1 where num>='0' and num<='9'  
    order by id desc  
*/

declare @dx_unit   varchar(12)   ,@result varchar(255) 
select  @result  = '' 
 
declare cursor1 cursor  for 
  select dx+unit as dx_unit  from #tmp1 where num>='0' and num<='9'  
    order by id desc  for read only 
open cursor1  
 
fetch cursor1 into @dx_unit       
while @@SQLSTATUS =0      
begin 
  select @result = @result +ltrim(rtrim(@dx_unit)) 
      
  fetch  cursor1 into @dx_unit  
end 
close cursor1  
DEALLOCATE cursor cursor1 
 
--select  @result 
while(charindex('零亿',@result)>0) 
begin 
  select @result =  stuff(@result,charindex('零亿',@result) ,4,'亿') 
end


while(charindex('零万',@result)>0) 
begin 
  select @result =  stuff(@result,charindex('零万',@result) ,4,'万') 
end

while(charindex('零仟',@result)>0) 
begin 
select @result =  stuff(@result,charindex('零仟',@result) ,4,'零') 
end
while(charindex('零佰',@result)>0) 
begin 
select @result =  stuff(@result,charindex('零佰',@result) ,4,'零') 
end
while(charindex('零拾',@result)>0) 
begin 
select @result =  stuff(@result,charindex('零拾',@result) ,4,'零') 
end
while(charindex('零元',@result)>0) 
begin 
select @result =  stuff(@result,charindex('零元',@result) ,4,'元') 
end
while(charindex('零万',@result)>0) 
begin 
  select @result =  stuff(@result,charindex('零万',@result) ,4,'万') 
end

while(charindex('零角',@result)>0) 
begin 
select @result =  stuff(@result,charindex('零角',@result) ,4,'零') 
end
while(charindex('零分',@result)>0) 
begin 
select @result =  stuff(@result,charindex('零分',@result) ,4,'零') 
end

while(charindex('零零',@result)>0) 
begin 
  select @result = stuff(@result,charindex('零零',@result) ,4,'零')  
end 

while(charindex('亿万',@result)>0) 
begin 
  select @result =  stuff(@result,charindex('亿万',@result) ,4,'亿') 
end



if @convmoney = convert(numeric(12,0),@convmoney) --整数  
select @result   = substring( @result ,  1 ,  charindex('元',@result)+1)+'整' 
select @result= ltrim(rtrim(@result)) 
 
--解决只有小数的情况 
select @result = ltrim(rtrim(@result)) 
if @result like '元%' 
begin 
 select @result   =substring( @result , 3 ,datalength(@result)-2) 
 select @result= ltrim(rtrim(@result)) 
end 
--去第一个零 
if @result like '零%' 
begin 
  select @result   = substring( @result ,  3,datalength(@result)-2) 
  select @result &nbs

[1] [2]  下一页


[Delphi程序]Rave Report中文版插件 V0.1  [Web开发]ShadowStar Fast Editor V0.1
[MySql]Linux网络服务软件安装备忘录 ver 0.1  
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Sql Server  · MySql
    · Access  · ORACLE
    · SyBase  · 其他
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台