Goran Bibic

Goran Bibic

  • 455
  • 2.9k
  • 178k

Add to one table mssql

Jul 20 2019 11:00 AM
My code is
 
  1. select x1.poslovni_partner,   
  2. CONVERT(decimal(16,2),(ISNULL(x1.ULR,0))) AS 'UL. roba',   
  3. CONVERT(decimal(16,2),(ISNULL(x2.ULRO, 0))) as 'ULR. ostalo',   
  4. CONVERT(decimal(16,2),(ISNULL(x3.ULRM, 0))) as 'UL. Repromaterijal',  
  5. CONVERT(decimal(16, 2), (ISNULL(ULR, 0) + (ISNULL(ULRO, 0) + (ISNULL(ULRM, 0))))) as 'Saldo'    
  6. from (select poslovni_partner, sum(iznos_sa_porezom) as ULR from(select poslovni_partner as poslovni_partner,  iznos_sa_porezom from dbo.mp_ulazni_racun_roba_lista where redni_broj  IS NOT NULL) a group by poslovni_partner) as x1 JOIN  
  7. (select poslovni_partner, sum(iznos_sa_porezom) as ULRO from (select poslovni_partner as poslovni_partner,iznos_sa_porezom from dbo.mp_ulazni_racun_ostalo_lista where redni_broj  IS NOT NULL) b group by poslovni_partner) as x2 on x1.poslovni_partner = x2.poslovni_partner JOIN  
  8. (select poslovni_partner, sum(iznos_sa_porezom) as ULRM from (select poslovni_partner as poslovni_partner,iznos_sa_porezom from dbo.mp_ulazni_racun_repromaterijal_lista where redni_broj  IS NOT NULL) b group by poslovni_partner) as  x3 on x1.poslovni_partner = x3.poslovni_partner 
 Result is
 
  1. poslovni_partner    UL. roba    ULR. ostalo    UL. Repromaterijal      Saldo  
  2. MOZZART  DOO          630.20        93.60            292.50           1016.30 
poslovni_partner is bussines partner on english
 
Need for all partners in this 3 tables.
Result is IF have partners in all tables...if not exist i one of tables dont show him...
If not exist in one table need to show 0.00
some help please?

Answers (2)