Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with recursive SQL Statement
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
01021429
Message ID:
01021567
Vues:
23
That's what I thought but if I group by descarga I still get the same results beside not all the records show.


>That's because you group by dt1.cuenta,dt1.descarga instead of dt1.descarga.
>
>>I've modified it like this:
>>
>>
>>Select dt1.Cuenta,dt1.Descarga,Sum(Balance) From (Select A.Cuenta,A.Descripcion,
>>Isnull((Select Balance From CNTBal03 Where Cuenta=A.Cuenta And Periodo=12 and Fiscal='2003' ),0)
>>+Isnull((Select Sum(Debito-Credito) From CNTDET02 Where Cuenta=A.Cuenta And Periodo=1 And Fiscal='2004'),0)+
>>Isnull((Select Sum(Debito-Credito) From CNTDET02 Where Cuenta IN (Select Cuenta From CNTCuentas Where Descarga=A.Cuenta) And Periodo=1 And Fiscal='2004'),0)
>> As Balance, A.Descarga From cntcuentas A) dt1
>>Group by dt1.cuenta,dt1.descarga
>>Order By rTrim(lTrim(dt1.Cuenta))
>>
>>
>>But I'm still having problems at the top levels, the totals are ok in the lower level but the upper levels are still getting wrong results.
>>
>>For example in the following tree
>>
>>
>>Account        Parent
>>1
>>10             1
>>100            10
>>100-01         100
>>100-02         100
>>100-03         100
>>100-04         100
>>100-04-01      100-04
>>100-04-02      100-04
>>100-04-03      100-04
>>
>>
>>The totals for all sub accounts are correct but the totals for account 1,10 and 100 are incorrect. Anyway I think I'm closer now.
I'm a mixture of Albert Einstein and Arnold Schwarzenegger. The only trouble is that I got Einstein's body and Schwarzenegger's brain
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform