Quantcast
Channel: SCN : Unanswered Discussions - Reporting and Printing
Viewing all articles
Browse latest Browse all 776

Doubled result on Query

$
0
0

Dear Experts,

 

Can anyone tell what is wrong with my query?

 

The original query gave me the correct result i needed, then when I added the CRD1 table 2 of the invoices got doubled.

 

SELECT 'IN' "IN/CN",T0.[DocNum],T2.[GroupName],  T0.[DocStatus], T0.[DocDate], T0.[DocDueDate], T0.[CardCode], T0.[CardName], T3.[Dscription], T3.[Quantity], T3.[LineTotal], T0.[PaidToDate], (T0.[DocTotal]-T0.[PaidToDate]) AS "Balance", T0.[Comments], T6.[Building]

FROM OINV T0

INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode

INNER JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode

INNER JOIN INV1 T3 ON T0.DocEntry = T3.DocEntry

INNER JOIN OITM T4 ON T3.ItemCode = T4.ItemCode

INNER JOIN OITB T5 ON T4.ItmsGrpCod = T5.ItmsGrpCod

INNER JOIN CRD1 T6 ON T1.CardCode = T6.CardCode

WHERE T5.[ItmsGrpNam] =[%0] AND  T0.[DocDate] BETWEEN [%1] and [%2] AND  T0.[CardName] <> 'CASH SALES'

 

UNION ALL

 

SELECT 'CN', T0.[DocNum],T2.[GroupName],  T0.[DocStatus], T0.[DocDate], T0.[DocDueDate], T0.[CardCode], T0.[CardName], T3.[Dscription], -T3.[Quantity], -T3.[LineTotal], -T0.[PaidToDate], -(T0.[DocTotal]-T0.[PaidToDate] ) AS "Balance", T0.[Comments], T6.[Building]

FROM ORIN T0

INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode

INNER JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode

INNER JOIN RIN1 T3 ON T0.DocEntry = T3.DocEntry

INNER JOIN OITM T4 ON T3.ItemCode = T4.ItemCode

INNER JOIN OITB T5 ON T4.ItmsGrpCod = T5.ItmsGrpCod

INNER JOIN CRD1 T6 ON T1.CardCode = T6.CardCode

WHERE T5.[ItmsGrpNam] =[%0] AND  T0.[DocDate] BETWEEN [%1] and [%2] AND  T0.[CardName] <> 'CASH SALES'


Viewing all articles
Browse latest Browse all 776


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>