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 ... 
随机推荐
- POJ 3349 Snowflake Snow Snowflakes(简单哈希)
			Snowflake Snow Snowflakes Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 39324 Accep ... 
- Let & Const
			Let & Const let 基础用法 很简单就能说明这个问题 if(false) { var a = 'heihei' } a = undefined if(true) { var a = ... 
- ionic  白屏
			昨天在发布新app的时候发现app在高版本的android的时候发现没有问题,在低版本的android 的时候发现存在白屏的情况,在run中alert,不能弹框,run不能运行, 参考这篇文章 ht ... 
- trigger中insert动作的测试
			Trigger为默认事务 测试环境:sql server 2008 r2 对象:DevList表 目标:确定trigger在数据库中有数据变化时是一次一批一批执行还是,按每条触发执行 测试需求: De ... 
- win7下安装和使用Windows XP Mode
			如果想在电脑中安装多个操作系统有几种方法: 1.安装虚拟机,继而在虚拟机中安装操作系统.虚拟机个数就相当于电脑个数,常用的虚拟机软件有VMVare,VMVare功能齐全,但是安装文件较大. 2.如果你 ... 
- Linux进程间通信(五):信号量 semget()、semop()、semctl()
			这篇文章将讲述别一种进程间通信的机制——信号量.注意请不要把它与之前所说的信号混淆起来,信号与信号量是不同的两种事物.有关信号的更多内容,可以阅读我的另一篇文章:Linux进程间通信 -- 信号.下面 ... 
- 【总结】虚拟机VirtualBox各种使用技巧
			作为个人学习研究,VirtualBox是首选,它是Oracle下免费的.开源.跨平台的一款虚拟机软件,小巧.实用,一点也不逊于商业版的VMware Workstation. VirtualBox官网: ... 
- TCP/IP四层模型
			转自:http://www.cnblogs.com/BlueTzar/articles/811160.html ISO制定的OSI参考模型的过于庞大.复杂招致了许多批评.与此对照,由技术人员自己开发的 ... 
- DirectAccess
			DirectAccess Direct Access 称为直接访问,它是Windows 7(企业版或者更高级版本)和Windows Server 2008 R2中的一项新功能.凭借这个功能,外网的用户 ... 
- gdbsever  使用说明
			gdbsever 使用说明 在新塘N3292x平台下 编译 gdbsever ./configure --target=arm-linux --host=arm-linux arm-linux-gdb ... 
