SBO小写金额转换中文大写SQL

select top 10 docnum 发票号,doctotal 发票总额,
replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(
                 case when doctotal=0 then N'零元' else '' end +
                case when left(right('00000000000'+convert(nvarchar(20),doctotal),16),1)='0'
                         then ''
                         else left(right('00000000000'+convert(nvarchar(20),doctotal),16),1) +N'亿'
                         end+
                case when left(right('00000000000'+convert(nvarchar(20),doctotal),15),1)='0'
                         then case        when left(right('00000000000'+convert(nvarchar(20),doctotal),15),2)<>'00' and doctotal>10000000
                                                then N'零'
                                                else N''
                                                end
                         else left(right('00000000000'+convert(nvarchar(20),doctotal),15),1) +N'百'
                         end+
                case when left(right('00000000000'+convert(nvarchar(20),doctotal),14),1)='0'
                         then case        when left(right('00000000000'+convert(nvarchar(20),doctotal),14),2)<>'00' and doctotal>1000000
                                                then N'零'
                                                else N''
                                                end
                         else left(right('00000000000'+convert(nvarchar(20),doctotal),14),1) +N'百'
                         end+
                case when left(right('00000000000'+convert(nvarchar(20),doctotal),13),1)='0'
                         then case        when left(right('00000000000'+convert(nvarchar(20),doctotal),13),2)<>'00' and doctotal>100000
                                                then N'零'
                                                else N''
                                                end
                         else left(right('00000000000'+convert(nvarchar(20),doctotal),13),1) +N'拾'
                         end+
                case when left(right('00000000000'+convert(nvarchar(20),doctotal),12),1)='0'
                         then case        when doctotal<10000
                                                then N''
                                                else N'万'
                                                end
                                       
                         else left(right('00000000000'+convert(nvarchar(20),doctotal),12),1) +N'万'
                         end+
               
                case when left(right('00000000000'+convert(nvarchar(20),doctotal),11),1)='0'
                         then case        when left(right('00000000000'+convert(nvarchar(20),doctotal),11),2)<>'00'  and doctotal>1000
                                                then N'零'
                                                else ''
                                                end
                         else left(right('00000000000'+convert(nvarchar(20),doctotal),11),1) +N'千'
                         end+
                case when left(right('00000000000'+convert(nvarchar(20),doctotal),10),1)='0'
                         then case        when left(right('00000000000'+convert(nvarchar(20),doctotal),10),2)<>'00' and doctotal>100
                                                then N'零'
                                                else N''
                                                end
                         else left(right('00000000000'+convert(nvarchar(20),doctotal),10),1) +N'百'
                         end+
               
                case when left(right('00000000000'+convert(nvarchar(20),doctotal),9),1)='0'
                         then case        when left(right('00000000000'+convert(nvarchar(20),doctotal),9),2)<>'00' and doctotal>10
                                                then N'零'
                                                else N''
                                                end
                         else left(right('00000000000'+convert(nvarchar(20),doctotal),9),1) +N'拾'
                         end+
               
                case when left(right('00000000000'+convert(nvarchar(20),doctotal),8),1)='0'
                         then case        when doctotal<1
                                                then N''
                                                else N'元'
                                                end
                                       
                         else left(right('00000000000'+convert(nvarchar(20),doctotal),8),1) +N'元'
                         end+
               
                case when left(right('00000000000'+convert(nvarchar(20),doctotal),6),1)='0'
                         then case        when doctotal<0.1        then ''
                                                when doctotal>1 and convert(int,doctotal)=doctotal then N'整'
                                               
                                                else N'零'
                                                end
                         else left(right('00000000000'+convert(nvarchar(20),doctotal),6),1) +N'角'
                         end+
                case when left(right('00000000000'+convert(nvarchar(20),doctotal),5),1)='0'
                         then ''       
                         else        left(right('00000000000'+convert(nvarchar(20),doctotal),5),1) +N'分' 
                         end
,0,N'零'),1,N'壹'),2,N'贰'),3,N'叁'),4,N'肆'),5,N'伍'),6,N'陆'),7,N'柒'),8,N'捌'),9,N'玖') 发票总额大写
from oinv

你可能感兴趣的:(数据库,休闲,Sbo,SBO小写金额,sbo软件)