 SELECT H.OZELKOD2 AS IHALE,H.KODU, H.ACIKLAMA,H.ACIKLAMA2, H.ACIKLAMA3, H.EK1, H.EK2,  H.EK3, H.EK4, 'TL' AS DVZ, (SELECT SUM(ALACAK)FROM HESAPISL2 WHERE HESAPISL2.SKODU='01' AND KODU=H.KODU GROUP BY KODU) AS HFATURA, (SELECT SUM(BORC)  FROM HESAPISL2 WHERE HESAPISL2.SKODU='01' AND KODU=H.KODU GROUP BY KODU) AS HODEME, (SELECT SUM(HI.ALACAK) FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=0)) AS TOPFATURA, (SELECT SUM(HI.BORC)  FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=0)) AS TOPODEME , ((SELECT SUM(HI.ALACAK) FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=0))- (SELECT SUM(HI.BORC)  FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=0))) AS BAKIYE , (SELECT SUM(HI.ALACAK-HI.KAPANAN) FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>= 0) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )<=15)) AS BORC15ALTI, (SELECT SUM(HI.ALACAK-HI.KAPANAN) FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=16) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )<=30)) AS BORC1630, (SELECT SUM(HI.ALACAK-HI.KAPANAN) FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=31) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )<=45)) AS BORC3145, (SELECT SUM(HI.ALACAK-HI.KAPANAN) FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=46) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )<=60)) AS BORC4660, (SELECT SUM(HI.ALACAK-HI.KAPANAN) FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=61) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )<=90)) AS BORC6190, (SELECT SUM(HI.ALACAK-HI.KAPANAN) FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=91)) AS BORC91USTU FROM HESAP AS H WHERE H.KODU LIKE '320%' AND  (((SELECT SUM(ALACAK)FROM HESAPISL2 WHERE HESAPISL2.SKODU='01' AND KODU=H.KODU GROUP BY KODU)-(SELECT SUM(BORC)  FROM HESAPISL2 WHERE HESAPISL2.SKODU='01' AND KODU=H.KODU GROUP BY KODU))>0) AND   H.KODU IN (SELECT DISTINCT HESAPISL2.KODU FROM HESAPISL2 WHERE  HESAPISL2.SKODU='01' AND (1=1) AND HESAPISL2.KODU LIKE  '320%' ) AND (SELECT SUM(HI.ALACAK) FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=0)) IS NOT NULL AND ((SELECT SUM(HI.ALACAK) FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=0))-(SELECT SUM(HI.BORC)  FROM HESAPISL2 AS HI WHERE HI.SKODU='01' AND (HI.KODU=H.KODU) AND (( CAST(CAST('12.26.2007' AS SMALLDATETIME) AS FLOAT) - CAST(TARIH AS FLOAT) )>=0)))>0.1 ORDER BY H.KODU

 Elektra              
                                                                                                                                                        Saat        : [BUSAAT]

                   MERKEZ  Satıcılar Yaşlandırma Raporu (26.12.2007)

 Kodu                Hesap Adı                   Döviz Toplam Fatura  Toplam Ödeme   Bakiye         Borç 0-15      Borç 16-30   Borç 31-45   Borç 46-60   Borç 61-90   Borç 90+
 ------------------- --------------------------- ----- -------------- -------------- -------------- -------------- ------------ ------------ ------------ ------------ --------------- 
{[KODU             ] [ACIKLAMA                 ] [DVZ] [~2TOPFATURA ] [~2TOPODEME  ] [~2BAKIYE    ] [~2BORC15ALTI] [~2BORC1630] [~2BORC3145] [~2BORC4660] [~2BORC6190] [~2BORC91USTU ]}[IHALE]
