cancel
Showing results for 
Search instead for 
Did you mean: 

Sales by Bill To State Query question

Former Member
0 Kudos

I have the following query that shows sales by Bill to State for a specified period of time.

SELECT T2.[State] AS 'Bill-To State', SUM(T0.[Max1099]) AS 'Gross Sales Amount' FROM  [dbo].[OINV] T0  INNER  JOIN [dbo].[OCRD] T1  ON  T1.[CardCode] = T0.[CardCode]  INNER  JOIN [dbo].[CRD1] T2  ON  T2.[CardCode] = T1.[CardCode]  AND  T2.[Address] = T0.[PayToCode]   WHERE T1.[GroupCode] <> 28 AND T0.[DocDate]>=[%0] AND T0.[DocDate]<=[%1] AND T2.[AdresType]='B' GROUP BY T2.[State]

If I create another query to capture credit memos (below), I get the following error:

"Can not add row without complete selection of batch/serial numbers"

SELECT T2.[State] AS 'Bill-To State', SUM(T0.[Max1099]) AS 'Gross Sales Amount' FROM  [dbo].[ORIN] T0  INNER  JOIN [dbo].[OCRD] T1  ON  T1.[CardCode] = T0.[CardCode]  INNER  JOIN [dbo].[RIN1] T2  ON  T2.[CardCode] = T1.[CardCode]  AND  T2.[Address] = T0.[PayToCode]   WHERE T1.[GroupCode] <> 28 AND T0.[DocDate]>=[%0] AND T0.[DocDate]<=[%1] AND T2.[AdresType]='B' GROUP BY T2.[State]



Does anyone have advice?


Thanks


Gary

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Gary,

[RIN1] is not the right table to join. It is CRD1.


Thanks,

Gordon

Answers (3)

Answers (3)

Former Member
0 Kudos

Thank you so much for the advice on the incorrect table in the query.

It works correctly now.

Gary

KennedyT21
Active Contributor
0 Kudos

Try This

SELECT T2.[State] AS 'Bill-To State',

   SUM(T0.[Max1099]) AS 'Gross Sales Amount'

FROM [dbo].[ORIN] T0

INNER  JOIN [dbo].[OCRD] T1 ON T1.[CardCode] = T0.[CardCode]

INNER  JOIN [dbo].[CRD1] T2 ON T2.[CardCode] = T1.[CardCode]

AND T2.[Address] = T0.[PayToCode]

WHERE T1.[GroupCode] <> 28

  AND T0.[DocDate]>=[%0]

  AND T0.[DocDate]<=[%1]

  AND T2.[AdresType]='B'

GROUP BY T2.[State]



Regards,

Kennedy

former_member212181
Active Contributor
0 Kudos

Hi Gary,

Please try below Query.

SELECT T2.[State] AS 'Bill-To State', SUM(T0.[Max1099]) AS 'Gross Sales Amount'

FROM  [dbo].[ORIN] T0

  INNER  JOIN [dbo].[OCRD] T1  ON  T1.[CardCode] = T0.[CardCode]

  INNER  JOIN [dbo].[CRD1] T2  ON  T2.[CardCode] = T1.[CardCode] AND  T2.[Address] = T0.[PayToCode]

WHERE T1.[GroupCode] <> 28

  AND T0.[DocDate]>=[%0] AND T0.[DocDate]<=[%1]

  AND T2.[AdresType]='B'

GROUP BY T2.[State]

Thanks

Unnikrishnan