SQL数字转英文函数
- -- 数字转英文
- -- =============================================
- -- Author: qianjin036a
- -- Create date:06/14/2008 02:27:17
- -- Description:Arabic numerals to English
- -- =============================================
- Go
- --创建函数
- CREATE FUNCTION Digit2English
- (
- @arabia decimal(38,17)
- )
- RETURNS varchar(1000)
- AS
- BEGIN
- declare @atoe table(a int,e varchar(10))
- insert into @atoe select 0,'zero' union all select 1,'one'
- union all select 2,'two' union all select 3,'three'
- union all select 4,'four' union all select 5,'five'
- union all select 6,'six' union all select 7,'seven'
- union all select 8,'eight' union all select 9,'nine'
- declare @integer bigint,@trillion int,@billion int,@million int,@thousand int,@hundred int,@english varchar(1000)
- select @integer=@arabia,@english=''
- select @trillion=@integer % 1000000000000000/1000000000000,@billion=@integer % 1000000000000/1000000000,
- @million=@integer % 1000000000/1000000,@thousand=(@integer % 1000000)/1000,@hundred=(@integer % 1000)
- if @trillion>0
- set @english=@english + dbo.ThreeDigit(@trillion) + 'trillion '
- if @billion>0
- set @english=@english + dbo.ThreeDigit(@billion) + 'billion '
- if @million>0
- set @english=@english + dbo.ThreeDigit(@million) + 'million '
- if @thousand>0
- set @english=@english + dbo.ThreeDigit(@thousand) + 'thousand '
- if @hundred>0
- set @english=@english + dbo.ThreeDigit(@hundred)
- if @english=''
- set @english='zero '
- if @arabia-@integer>0.000000000
- begin
- declare @decimal decimal(18,17)
- select @english=@english+'point ',@decimal=@arabia-@integer
- while @decimal>0.0
- begin
- select @english=@english+e+' ' from @atoe where cast(@decimal*10 as int)=a
- set @decimal=@decimal*10-cast(@decimal*10 as int)
- end
- end
- return @english
- END
- GO
- -- =============================================
- -- Author: qianjin036a
- -- Create date: 06/14/2008 02:27:17
- -- Description: Three Digit Arabic numerals to English
- -- =============================================
- CREATE FUNCTION ThreeDigit
- (
- @integer int
- )
- RETURNS varchar(100)
- WITH EXECUTE AS CALLER
- AS
- BEGIN
- declare @atoe table(a int,e varchar(10))
- insert into @atoe select 0,'zero' union all select 1,'one'
- union all select 2,'two' union all select 3,'three'
- union all select 4,'four' union all select 5,'five'
- union all select 6,'six' union all select 7,'seven'
- union all select 8,'eight' union all select 9,'nine'
- union all select 10,'ten' union all select 11,'eleven'
- union all select 12,'twelve' union all select 13,'thirteen'
- union all select 14,'fourteen' union all select 15,'fifteen'
- union all select 16,'sixteen' union all select 17,'seventeen'
- union all select 18,'eighteen' union all select 19,'nineteen'
- union all select 20,'twenty' union all select 30,'thirty'
- union all select 40,'forty' union all select 50,'fifty'
- union all select 60,'sixty' union all select 70,'severty'
- union all select 80,'eighty' union all select 90,'ninety'
- declare @english varchar(100)
- set @english=''
- if @integer>99
- begin
- select @english=e+' hundred ' from @atoe where @integer/100=a
- set @integer=@integer % 100
- if @integer>0
- set @english=@english+'and '
- end
- if @integer<=20 and @integer>0
- select @english=@english+e+' ' from @atoe where @integer=a
- if @integer>20
- begin
- select @english=@english+e+' ' from @atoe where @integer/10*10=a
- set @integer=@integer % 10
- if @integer>0
- select @english=@english+e+' ' from @atoe where @integer=a
- end
- RETURN @english
- END
- GO
- select dbo.digit2english(123456789987654.321)
- union all select dbo.digit2english(120045080045054.8412)
- union all select dbo.digit2english(0.0102541)
- go
- /*
- ---------------------------------------------------------------------
- one hundred and twenty three trillion four hundred and fifty six billion seven hundred and eighty nine million nine hundred and eighty seven thousand six hundred and fifty four point three two one
- one hundred and twenty trillion forty five billion eighty million forty five thousand fifty four point eight four one two
- zero point zero one zero two five four one
- */
SQL数字转英文函数的更多相关文章
- SQL Server:字符串函数
以下所有例子均Studnet表为例: 1. len():计算字符串长度 len()用来计算字符串的长度,每个中文汉字或英文字母都为一个长度 select sname, len(sname) from ...
- 你真的会玩SQL吗?实用函数方法汇总
你真的会玩SQL吗?系列目录 你真的会玩SQL吗?之逻辑查询处理阶段 你真的会玩SQL吗?和平大使 内连接.外连接 你真的会玩SQL吗?三范式.数据完整性 你真的会玩SQL吗?查询指定节点及其所有父节 ...
- sql server中常用方法函数
SQL SERVER常用函数 1.DATEADD在向指定日期加上一段时间的基础上,返回新的 datetime 值. (1)语法: DATEADD ( datepart , number, date ) ...
- SQL Server 内置函数、临时对象、流程控制
SQL Server 内置函数 日期时间函数 --返回当前系统日期时间 select getdate() as [datetime],sysdatetime() as [datetime2] getd ...
- sql server 常用的函数小汇
摘录些许sqlserver 常用到的一些函数,便于日常学习使用 一.字符转换函数1.ASCII()返回字符表达式最左端字符的ASCII 码值.在ASCII()函数中,纯数字的字符串可不用‘’括起来,但 ...
- excel如何用公式判断单元格的值是否为数字、英文、中文,以及相应的计数
一.excel如何用公式判断单元格的值是否为数字.英文.中文. A列为数据列,B列为判断列=LOOKUP(CODE(ASC(A1)),{48,65,123;"数字","英 ...
- 10、SQL Server 内置函数、临时对象、流程控制
SQL Server 内置函数 日期时间函数 --返回当前系统日期时间 select getdate() as [datetime],sysdatetime() as [datetime2] getd ...
- SQL点滴30—SQL中常用的函数
原文:SQL点滴30-SQL中常用的函数 该文章转载自http://www.cnblogs.com/jiajiayuan/archive/2011/06/16/2082488.html 别人的总结,很 ...
- Sql server 经典常用函数
..STUFF()用另一子串替换字符串指定位置.长度的子串.STUFF (<character_expression1>, <start_ position>, <len ...
随机推荐
- ssh reverse tunnel
ssh反向通道的可用场景之一:从外网访问内网的主机.所必须的是你需要一个有ssh登录权限的公网主机. 步骤如下(将内网主机称作A,公网ssh主机地址为hostP ): 1.在内网A上执行 :local ...
- JavaScript的学习资料
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript http://www.liaoxuefeng.com/wiki/001434446689 ...
- Java框架Struts2
struts2的核心和工作原理 在学习struts2之前,首先我们要明白使用struts2的目的是什么?它能给我们带来什么样的好处? 设计目标 Struts设计的第一目标就是使MVC模式应用于we ...
- (转)理解MySQL——索引与优化
参考资料:http://www.cnblogs.com/hustcat/archive/2009/10/28/1591648.html ———————————— 全文: 写在前面:索引对查询的速度有着 ...
- 在linux命令行下执行php 程序
如何在linux命令行下,执行php程序. 例子 打印当前时间 php -r "echo time()" 随机输出一个数字 php -r "echo rand(1,20) ...
- 安卓3D游戏-神奇宝贝防御战
我和同学用unity引擎做的,作为软件工程的大作业. 是一个花费金钱抓怪.控制怪物站位.击杀进攻的敌人获得金钱的类似塔防的安卓游戏. 下载地址:http://pan.baidu.com/s/1gdpH ...
- 大熊君大话NodeJS之------MongoDB模块(额外篇)
一,开篇分析 这篇属于扩展知识篇,因为在下面的文章中会用到数据库操作,所以今天就来说说它(Mongodb模块). (1),简介 MongoDB是一个基于分布式文件存储的数据库.由C++语言编写.旨在为 ...
- 利用Shodan和Censys进行信息侦查
在渗透测试的初始阶段,Shodan.Censys等在线资源可以作为一个起点来识别目标机构的技术痕迹.本文中就以二者提供的Python API为例,举例介绍如何使用它们进行渗透测试初期的信息侦查. Sh ...
- BZOJ 4581: [Usaco2016 Open]Field Reduction
Description 有 \(n\) 个点,删掉三个点后,求最小能围住的面积. Sol 搜索. 找出 左边/右边/上边/下边 的几个点枚举就可以了. 我找了 12 个点,统计一下坐标的个数,然后找到 ...
- PHP获取一年有几周以及每周开始日期和结束日期
最近接了一个项目,其中有一需求是用php获取一年有几周以及每周开始日期和接触日期.在网上找些资料没有合适的,于是自己做了一份,下面通过两种方式实现PHP获取一年有几周以及每周开始日期和结束日期 代码一 ...