Merhaba,
Sanırım bu işini tam görecek
Kolay gelsin
FORMBS
SELECT
CLNTC.DEFINITION_ 'Cari Hesap Ünvanı',
CLNTC.TAXOFFICE 'Vergi Dairesi',
INVFC.SPECODE 'Özel Kodu',
CLNTC.TAXNR 'Vergi Numarasy',
SUM(XXX.LNETSUM2) AS 'KDV Hariç Tutar',
SUM(XXX.FICHECOUNT2) AS 'Fi? Sayysy'
FROM
(SELECT
INVFC.CLIENTREF,
COUNT(DISTINCT INVFC.LOGICALREF) AS FICHECOUNT2,
SUM((INVFC.NETTOTAL-INVFC.TOTALVAT)) AS LNETSUM2
FROM
LG_002_01_INVOICE INVFC WITH(NOLOCK) WHERE
INVFC.STATUS = 0 AND
INVFC.TRCODE IN (6,7,8,9,10,14) AND
INVFC.NETTOTAL <> 0 AND
INVFC.CLIENTREF <> 0 AND
INVFC.CANCELLED = 0 AND
INVFC.DATE_ >= CONVERT(dateTime, '1-1-2007', 101) AND
(INVFC.DATE_ <= CONVERT(dateTime, '12-31-2007', 101))
GROUP BY INVFC.CLIENTREF) XXX LEFT OUTER JOIN LG_002_CLCARD CLNTC WITH(NOLOCK) ON (XXX.CLIENTREF = CLNTC.LOGICALREF)
GROUP BY CLNTC.DEFINITION_,CLNTC.TAXOFFICE,CLNTC.TAXNR,CLNTC.LOGICALREF HAVING SUM(XXX.LNETSUM2) >= 30000
ORDER BY CLNTC.DEFINITION_
FORMBA
SELECT
CLNTC.DEFINITION_ 'Cari Hesap Ünvanı',
CLNTC.TAXOFFICE 'Vergi Dairesi',
CLNTC.TAXNR 'Vergi Numarasý',
INVFC.SPECODE 'Özel Kodu',
SUM(XXX.LNETSUM2) AS 'KDV Hariç Tutar',
SUM(XXX.FICHECOUNT2) AS 'Fiþ Sayýsý'
FROM
(SELECT
INVFC.CLIENTREF,
COUNT(DISTINCT INVFC.LOGICALREF) AS FICHECOUNT2,
SUM((INVFC.NETTOTAL-INVFC.TOTALVAT)) AS LNETSUM2
FROM
LG_XXX_YY_INVOICE INVFC WITH(NOLOCK) WHERE
INVFC.STATUS = 0 AND
INVFC.TRCODE IN (1,2,3,4,5,13,26) AND
INVFC.NETTOTAL <> 0 AND
INVFC.CLIENTREF <> 0 AND
INVFC.CANCELLED = 0 AND
INVFC.DATE_ >= CONVERT(dateTime, '1-1-2007', 101) AND
(INVFC.DATE_ <= CONVERT(dateTime, '12-31-2007', 101))
GROUP BY INVFC.CLIENTREF) XXX LEFT OUTER JOIN LG_XXX_CLCARD CLNTC WITH(NOLOCK) ON (XXX.CLIENTREF = CLNTC.LOGICALREF)
GROUP BY CLNTC.DEFINITION_,CLNTC.TAXOFFICE,CLNTC.TAXNR,CLNTC.LOGICALREF HAVING SUM(XXX.LNETSUM2) >= 30000
ORDER BY CLNTC.DEFINITION_