--Digital to English--=============================================--author:qianjin036a--Create date:06/14/2008 02:27:17--Des Cription:arabic numerals to english--=============================================go--creating functions Create function Digit2english (@arabia decimal (38,17)) RETURNS varchar (Asbegin declare @atoe table (a int,e varchar) inser T into @atoe Select 0, ' zero ' union ALL select 1, ' One ' union ALL select 2, ' Both ' 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, @billi on int, @million int, @thousand int, @hundred int, @english varchar select @[email protected], @english = ' SE Lect @[email protected]% 1000000000000000/1000000000000,@[email protected]% 1000000000000/1000000000, @ [email protected]% 1000000000/1000000, @thousand = (@integer% 1000000)/1000, @hundred = (@integer%) if @trillion >0 set @[email protected ] + dbo. Threedigit (@trillion) + ' trillion ' if @billion >0 set @[email protected] + dbo. Threedigit (@billion) + ' billion ' if @million >0 set @[email protected] + dbo. Threedigit (@million) + ' million ' if @thousand >0 set @[email protected] + dbo. Threedigit (@thousand) + ' thousand ' if @hundred >0 set @[email protected] + dbo. Threedigit (@hundred) If @english = ' Set @english = ' zero ' if @[email protected]>0.000000000 beg In declare @decimal decimal (18,17) Select @[email protected]+ ' point ', @[email protected]@i Nteger while @decimal >0.0 begin select @[email protected]+e+ "from @atoe where cast (@decimal *10 as int) =a set @[email protected]*10-cast (@decimal *10 as int) End end return @englishENDGO--=============================================--author:qianjin03 6a--Create date:06/14/2008 02:27:17--description:three Digit Arabic numerals to english--============================ =================create FUNCTION threedigit (@integer int) RETURNS varchar (+) with EXECUTE as Callerasbegin declare @atoe table (a int,e varchar) insert into @atoe Select 0, ' zero ' union ALL select 1, ' One ' union ALL select 2, ' TW O ' UNION ALL select 3, ' Three ' union ALL select 4, ' Four ' union ALL select 5, ' Five ' union ALL SEL ECT 6, ' Six ' union ALL select 7, ' Seven ' union ALL select 8, ' Eight ' union ALL select 9, ' nine ' Unio n All SELECT, ' Ten ' union ALL Select one, ' Eleven ' union ALL Select, ' Twelve ' union ALL Select, ' t Hirteen ' UNION ALL Select, ' Fourteen ' union ALL Select, ' Fifteen ' union ALL Select, ' sixteen ' union All SELECT, ' SeventeeN ' union ALL Select, ' Eighteen ' union ALL Select, ' Nineteen ' union All Select, ' Twenty ' union ALL Select a, ' Thirty ' union ALL Select, ' Forty ' union ALL SELECT, ' Fifty ' union ALL SELECT, ' Sixty ' UNION ALL select the ' severty ' union ALL Select A, ' Eighty ' union ALL Select, ' Ninety ' declare @english varchar set @english = "If @integer >99 begin select @english =e+ ' hundred ' from @atoe wher E @integer/100=a set @[email protected]% if @integer >0 set @[email protected]+ ' and ' End If @integer <=20 and @integer >0 select @[email protected]+e+ ' from @ato e where @integer =a if @integer >20 begin select @[email protected]+e+ ' from @atoe where @int Eger/10*10=a set @[email protected]% if @integer >0 select @[email pr Otected]+e+ ' from @atoe where @integer =a end RETURN @englishENDGO Select Dbo.digit2english (123456789987654.321) union ALL Select Dbo.di Git2english (120045080045054.8412) union ALL Select Dbo.digit2english (0.0102541) go/*------------------------------- --------------------------------------One hundred and twenty three trillion four hundred and fifty six billion seven Hundr Ed and eighty nine million nine hundred and eighty seven thousand six hundred and fifty four point three, Oneone Hundre D and twenty trillion forty five billion eighty million forty five thousand fifty four point eight four one twozero point Zero One zero-five four one*/
SQL Digital to English function