日期:2014-05-16 浏览次数:20535 次
with p as (
select 'B' suffix,0 pr union all
select 'KB' ,1 pr union all
select 'MB' ,2 pr union all
select 'GB' ,3 pr union all
select 'TB' ,4 pr
)
,TestData as (
select 12345678901111111 SendMTTRAFFIC,523456789011122 SendCUTRAFFIC,124345678901111 SendCTTRAFFIC union all
select 7811,4444,77777777 union all
select 212142546,4444,77777777 union all
select 0,5454222,1022 union all
select 1111,4444,31 union all
select 1024,4444,77777777 union all
select 1048576,52,0 union all
select 1025,4444,77777777 union all
select 1099511627776,0,2
)
select t.SendMTTRAFFIC
,convert(varchar(50), CAST(round(t.SendMTTRAFFIC/POWER(cast(1024 as bigint),p.pr),2) as float)) +p.suffix strSendMTTRAFFIC
,t.SendCUTRAFFIC
,convert(varchar(50), CAST(round(t.SendCUTRAFFIC/POWER(cast(1024 as bigint),p2.pr),2) as float)) +p2.suffix strSendCUTRAFFIC
,t.SendCTTRAFFIC
,convert(varchar(50), CAST(round(t.SendCTTRAFFIC/POWER(cast(1024 as bigint),p3.pr),2) as float)) +p3.suffix strSendCTTRAFFIC
from TestData t
cross join p
cross join p p2
cross join p p3
where (t.SendMTTRAFFIC/POWER(cast(1024 as bigint),p.pr)<1024 and t.SendMTTRAFFIC/POWER(cast(1024 as bigint),p.pr)>=1 or (SendMTTRAFFIC=0 and p.pr=0) or (SendMTTRAFFIC>=1125899906842624 and p.pr=4))
and (t.SendCUTRAFFIC/POWER(cast(1024 as bigint),p2.pr)<1024 and t.SendCUTRAFFIC/POWER(cast(1024 as bigint),p2.pr)>=1 or (SendCUTRAFFIC=0 and p2.pr=0) or (SendMTTRAFFIC>=1125899906842624 and p2.pr=4))
and (t.SendCTTRAFFIC/POWER(cast(1024 as bigint),p3.pr)<1024 and t.SendCTTRAFFIC/POWER(cast(1024 as bigint),p3.pr)>=1 or (SendCTTRAFFIC=0 and p3.pr=0) or (SendMTTRAFFIC>=1125899906842624 and p3.pr=4))
order by SendMTTRAFFIC