Incorrect Syntax near the keyword 'SELECT'

I am trying to filter information in the container before feeding into the report, and return IC Item Pricing where the DPRICETYPE is 1 (to prevent two row of data for every item and having to add yet another filter into my already complex report filters).  

I learnt a new trick by following the helpful advice in  http://www.sageintelligencecommunity.com/forum/topics/simple-sql-expression .  

  • I created a simple container with only the ICPRIC & ICPRICP tables
  • then created a simple report with only the [ICPRICP].[UNITPRICE] field
  • filtered by DPRICETYPE.
  • switched to output mode
  • copied the sql output.
  • pasted into the expression in my original (more complex) container. 

SELECT   [ICPRICP].[UNITPRICE]
FROM   (([ICPRIC] INNER JOIN [ICPRICP]
ON [ICPRIC].[ITEMNO] = [ICPRICP].[ITEMNO] AND [ICPRIC].[PRICELIST] = [ICPRICP].[PRICELIST])
INNER JOIN [ICITEM]
ON [ICPRIC].[ITEMNO] = [ICITEM].[ITEMNO])

WHERE  ([ICPRICP].[DPRICETYPE] = 1)

Error is [Microsoft][ODBC SQL Server Driver][SQL Server] Incorrect syntax near the keyword "SELECT'.

At this point, I am only applying one filter and I can't even get that to work.

Can anyone guide me on correct syntax??

Ultimately I want two expressions:

  1. Give me the unitprice where type = 1 and pricelist = "retail"
  2. Give me the unitprice where type = 1 and pricelist = "whsale"

so that the two columns come is side-by-side next each item on my report.

  • 0

    Thanks, I tried the brackets and got a different error.

    I will try and work out 'case' instead.

  • 0

    Hi Cathryn, when u pasted that select statment into your expression, did u encapsulate it in brackets  like so  

    (

    SELECT    [ICPRICP].[UNITPRICE]
    FROM   (([ICPRIC]  INNER JOIN [ICPRICP]
    ON [ICPRIC].[ITEMNO] = [ICPRICP].[ITEMNO] AND [ICPRIC].[PRICELIST] = [ICPRICP].[PRICELIST])
    INNER JOIN [ICITEM]
    ON [ICPRIC].[ITEMNO] = [ICITEM].[ITEMNO])

    WHERE  ([ICPRICP].[DPRICETYPE] = 1)

    )

    Im not sure of the exact context here but given what u ultimately want for those 2 expressions, that looks like a job for a case statement.