BS nin Query si:
SELECT
CLNTC.LOGICALREF,CLNTC.DEFINITION_,CLNTC.TAXNR,SUM(XXX.LNETSUM2) AS LNETSUM, SUM(XXX.FICHECOUNT2) AS FICHECOUNT
FROM
(SELECT
INVFC.CLIENTREF,COUNT(DISTINCT INVFC.LOGICALREF) AS FICHECOUNT2, SUM((INVFC.NETTOTAL-INVFC.TOTALVAT)) AS LNETSUM2
FROM
LG_800_01_INVOICE INVFC
WITH(NOLOCK)
WHERE
INVFC.STATUS = 0 AND (INVFC.TRCODE IN (6,7,8,9,10,11) OR ((INVFC.TRCODE = 13 AND INVFC.DECPRDIFF = 1) OR (INVFC.TRCODE = 14 AND INVFC.DECPRDIFF = 0))) AND INVFC.NETTOTAL <> 0 AND INVFC.CLIENTREF <> 0 AND INVFC.CANCELLED = 0 AND INVFC.DATE_ >= CONVERT(dateTime, '5-1-2008', 101) AND (INVFC.DATE_ <= CONVERT(dateTime, '5-31-2008', 101)) AND (INVFC.BRANCH IN (0))
GROUP BY
INVFC.CLIENTREF
UNION ALL SELECT
CTRNS.CLIENTREF,COUNT(DISTINCT CTRNS.LOGICALREF) AS FICHECOUNT2, SUM((CTRNS.AMOUNT*100)/(100+CTRNS.VATRATE)) AS LNETSUM2
FROM
LG_800_01_CLFLINE CTRNS WITH(NOLOCK) LEFT OUTER JOIN LG_800_01_CLFICHE CLFIC WITH(NOLOCK) ON (CLFIC.LOGICALREF = CTRNS.SOURCEFREF)
WHERE
CTRNS.CLIENTREF <> 0 AND ((CTRNS.TRCODE = 6 AND CTRNS.SIGN = 0) OR (CTRNS.TRCODE IN (45))) AND CTRNS.DATE_ >= CONVERT(dateTime, '5-1-2008', 101) AND (CTRNS.DATE_ <= CONVERT(dateTime, '5-31-2008', 101)) AND (CTRNS.BRANCH IN (0))
GROUP BY
CTRNS.CLIENTREF
) XXX LEFT OUTER JOIN LG_800_CLCARD CLNTC WITH(NOLOCK) ON (XXX.CLIENTREF = CLNTC.LOGICALREF)
GROUP BY
CLNTC.DEFINITION_,CLNTC.TAXNR,CLNTC.LOGICALREF
HAVING SUM(XXX.LNETSUM2) >= 8000
ORDER BY
CLNTC.DEFINITION_
BA nın Query si
SELECT
CLNTC.LOGICALREF,CLNTC.DEFINITION_,CLNTC.TAXNR,SUM(XXX.LNETSUM2) AS LNETSUM, SUM(XXX.FICHECOUNT2) AS FICHECOUNT
FROM
(SELECT
INVFC.CLIENTREF,COUNT(DISTINCT INVFC.LOGICALREF) AS FICHECOUNT2, SUM((INVFC.NETTOTAL-INVFC.TOTALVAT)) AS LNETSUM2
FROM
LG_800_01_INVOICE INVFC
WITH(NOLOCK)
WHERE
INVFC.STATUS = 0 AND (INVFC.TRCODE IN (1,2,3,4,5,12,26) OR (INVFC.TRCODE = 14 AND INVFC.DECPRDIFF = 1) OR (INVFC.TRCODE = 13 AND INVFC.DECPRDIFF = 0)) AND INVFC.NETTOTAL <> 0 AND INVFC.CLIENTREF <> 0 AND INVFC.CANCELLED = 0 AND INVFC.DATE_ >= CONVERT(dateTime, '7-1-2008', 101) AND (INVFC.DATE_ <= CONVERT(dateTime, '7-31-2008', 101)) AND (INVFC.BRANCH IN (0))
GROUP BY
INVFC.CLIENTREF
UNION ALL SELECT
CTRNS.CLIENTREF,COUNT(DISTINCT CTRNS.LOGICALREF) AS FICHECOUNT2, SUM((CTRNS.AMOUNT*100)/(100+CTRNS.VATRATE)) AS LNETSUM2
FROM
LG_800_01_CLFLINE CTRNS WITH(NOLOCK) LEFT OUTER JOIN LG_800_01_CLFICHE CLFIC WITH(NOLOCK) ON (CLFIC.LOGICALREF = CTRNS.SOURCEFREF)
WHERE
CTRNS.CLIENTREF <> 0 AND ((CTRNS.TRCODE = 6 AND CTRNS.SIGN = 1) OR (CTRNS.TRCODE IN (46))) AND CTRNS.DATE_ >= CONVERT(dateTime, '7-1-2008', 101) AND (CTRNS.DATE_ <= CONVERT(dateTime, '7-31-2008', 101)) AND (CTRNS.BRANCH IN (0))
GROUP BY
CTRNS.CLIENTREF
) XXX LEFT OUTER JOIN LG_800_CLCARD CLNTC WITH(NOLOCK) ON (XXX.CLIENTREF = CLNTC.LOGICALREF)
GROUP BY
CLNTC.DEFINITION_,CLNTC.TAXNR,CLNTC.LOGICALREF
HAVING SUM(XXX.LNETSUM2) >= 8000
ORDER BY
CLNTC.DEFINITION_
Exelden sql bağlantısı yapabilirsen olur.