Complex Query

SUGGESTED

Hello,

I am new to the world of Sage ERP.

I have designed this query and it works fine in SQL:

SELECT o1.*, (

Select isnull(SUM(D002_DollarsRented)+SUM(DollarsSold),0)
FROM openquery(TESTSWRMAS, 'select * from AR_CustomerSalesHistory') o2
WHERE FiscalYear=DATEPART(YYYY, GETDATE())
AND FiscalPeriod=DATEPART(MM, GETDATE())
AND o1.ARDivisionNo=o2.ARDivisionNo
AND o1.CustomerNo=o2.CustomerNo) AS SalesPTD,

(Select isnull(SUM(D002_DollarsRented)+SUM(DollarsSold),0)
FROM openquery(TESTSWRMAS, 'select * from AR_CustomerSalesHistory') o3
WHERE FiscalYear=DATEPART(YYYY, GETDATE())
AND o1.ARDivisionNo=o3.ARDivisionNo
AND o1.CustomerNo=o3.CustomerNo) AS SalesYTD,

(Select isnull(SUM(D002_DollarsRented)+SUM(DollarsSold),0)
FROM openquery(TESTSWRMAS, 'select * from AR_CustomerSalesHistory') o4
WHERE FiscalYear=DATEPART(YYYY, GETDATE())-1
AND o1.ARDivisionNo=o4.ARDivisionNo
AND o1.CustomerNo=o4.CustomerNo) AS SalesPYR

FROM AR_Customer o1

When I am trying to run this using Sage ERP MAS 200, it gives error:

Error Number: 1005


Description: 

[37000] SQL call failed. Expected lexical element not found: <identifier>

 

Native Error: 1015

 

Source: [ProvideX][ODBC Driver]

I think, complex queries are not allowed in ProvideX. How to deal with this?

 

Thanks!

Parents Reply Children
  • 0 in reply to Vikram

    could you please elaborate on what you're doing exactly? it sounds like you ran the query from sql server and it worked. what did you then do afterwards? what do you mean by "using sage erp mas 200"? for one thing, i know that "OPENQUERY" is not supported by providex's odbc driver.

  • 0 in reply to roastbeast
    SUGGESTED

    ...

    I am trying to achieve following:

    For each unique combination of ARDivisionNo and CustomerNo from AR_Customer, I am trying to get 3 things:

    1.  SalesPTD: Sum of D002_DollarsRented and DollarsSold from AR_CustomerSalesHistory for current month and current year.

    2. SalesYTD: Sum of D002_DollarsRented and DollarsSold from AR_CustomerSalesHistory for current year.

    3. SalesPYR: Sum of D002_DollarsRented and DollarsSold from AR_CustomerSalesHistory for previous year.

    You are correct. The query mentioned in the Q, which I initially constructed in SQL server, worked properly in SQL Server.

    Later, I tried to following version of the same in Scribe workbench in source, where source was Sage ERP MAS:

    SELECT o1.*, (

    Select isnull(SUM(D002_DollarsRented)+SUM(DollarsSold),0)

    FROM AR_CustomerSalesHistory o2

    WHERE FiscalYear=DATEPART(YYYY, GETDATE())

    AND FiscalPeriod=DATEPART(MM, GETDATE())

    AND o1.ARDivisionNo=o2.ARDivisionNo

    AND o1.CustomerNo=o2.CustomerNo) AS SalesPTD,

    (Select isnull(SUM(D002_DollarsRented)+SUM(DollarsSold),0)

    FROM  AR_CustomerSalesHistory o3

    WHERE FiscalYear=DATEPART(YYYY, GETDATE())

    AND o1.ARDivisionNo=o3.ARDivisionNo

    AND o1.CustomerNo=o3.CustomerNo) AS SalesYTD,

    (Select isnull(SUM(D002_DollarsRented)+SUM(DollarsSold),0)

    FROM AR_CustomerSalesHistory o4

    WHERE FiscalYear=DATEPART(YYYY, GETDATE())-1

    AND o1.ARDivisionNo=o4.ARDivisionNo

    AND o1.CustomerNo=o4.CustomerNo) AS SalesPYR

    FROM AR_Customer o1


    And yes...you are correct:  "OPENQUERY" is not supported by ProvideX's odbc driver. Hence, I have not included that in the query that I was trying in Scribe workbench on source side, where source is Sage ERP MAS.

     

    Please let me know if you need any other information from my side. 

     

    Thanks!