Here is my query - created through SAP Query tool:
SELECT DISTINCT
T1.CardCode,
T1.CardName,
T1.Phone1,
T1.GroupCode,
T1.Territory,
T2.Street,
T2.Block,
T2.City,
T2.ZipCode,
T2.County,
T2.State,
T2.Country,
count(distinct(T3.DocEntry)) as NumberOfInvoices,
sum(distinct(T4.GTotal)) as InvoiceTotal
FROM
[ASAP].[dbo].[OCRD] as T1
INNER JOIN [ASAP].[dbo].[CRD1] as T2 ON T1.CardCode = T2.CardCode
INNER JOIN [ASAP].[dbo].[OINV] as T3 on T1.CardCode = T3.CardCode
INNER JOIN [ASAP].[dbo].[INV1] as T4 on T3.DocEntry = T4.DocEntry
WHERE
T1.Territory = [%0]
AND T3.DocDate >= [%1]
AND T3.DocDate <= [%2]
GROUP BY
T1.CardCode,
T1.CardName,
T1.Phone1,
T1.GroupCode,
T1.Territory,
T2.Street,
T2.Block,
T2.City,
T2.ZipCode,
T2.County,
T2.State,
T2.Country
This is the Error I recieve - You can clearly see I have the field in the Group By:
- [Microsoft][SQL Native Client][SQL Server]Column 'ASAP.dbo.OCRD.Territory' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
- [Microsoft][SQL Native Client][SQL Server]Statement 'Serv
Please advise