Code check số dòng Sivip theo đơn vị

---Code tính dung lượng dựa vào 2 bảng ct00 và ct70
select ma_dvcs as ma_dvcs, count(stt_rec) as so_dong into #ct00 from ct00  group by  ma_dvcs 
select ma_dvcs as ma_dvcs, count(stt_rec) as so_dong into #ct70  from ct70  group by ma_dvcs 
select  distinct  ma_dvcs, stt_rec into #ct00_1 from ct00 

select max(ma_dvcs) as ma_dvcs, count(stt_rec) as so_chungtu into #ct00_2  from #ct00_1  group by ma_dvcs 


select a.ma_dvcs, max(c.ten_dvcs) as Ten_cty,max(e.ma_so_thue) as MST, sum(isnull(a.so_dong,0)+isnull(b.so_dong,0)) as so_dong,
	FORMAT(MAX(d.so_chungtu),'# 000') as so_chung_tu,   
	FORMAT(sum(isnull(a.so_dong,0)+isnull(b.so_dong,0)), '# 000') AS Số_dòng, 
	FORMAT(sum(isnull(a.so_dong,0)+isnull(b.so_dong,0))/50, '# 000') as MB,
	FORMAT( CAST (sum(isnull(a.so_dong,0)+isnull(b.so_dong,0))/50 AS  numeric(16,2))/1024, '#0.00') as GB
from #ct00 a left join #ct70 b on a.ma_dvcs = b.ma_dvcs left join dmdvcs c on a.ma_dvcs = c.ma_dvcs left join #ct00_2 d on a.ma_dvcs = d.ma_dvcs left join dmdvcskb e on a.ma_dvcs = e.ma_dvcs
--WHERE a.ma_dvcs = '0246'
group by a.ma_dvcs
order by so_dong desc

drop table #ct00
drop table #ct70
drop table #ct00_1
drop table #ct00_2
--@0 là MST, @1 là email, @2 là điện thoại
declare @0 nvarchar(11),@1 nvarchar(10),@2 nvarchar(1)
select @0= N'0400292124',@1= N'',@2= N''

EXEC rptdungluongbycus @0, @1, @2, 5, 1

-- Chạy code này trong CRM

Last updated

Was this helpful?