Skip to Content
0
Former Member
May 27, 2014 at 02:49 AM

Invalid Query Tree when leaving variable entry dialog empty (valueless)

34 Views

Hi Everyone,

I am receiving an 'Invalid query tree' error - as shown below - from my code (also shown below), but only when the 'Define survey variables' box is left blank.

i.e.: I leave the field blank,

then I get the error below,

finally here is the code in question -

DECLARE @ytdAmount int
SET @ytdAmount = '[%0]'
     IF @ytdAmount = ''
     SET @ytdAmount = '0'

SELECT T0.CardName, T0.CardCode, TotalSales - TotalCredits AS '$ YTD Sales'

FROM
(
SELECT T0.CardCode, T1.CardName, SUM(T0.DocTotal) 'TotalSales'
FROM AU.dbo.OINV T0
INNER JOIN AU.dbo.OCRD T1 ON T1.CardCode = T0.CardCode

WHERE Year(T0.DocDate) = Year(Getdate())

GROUP BY T0.CardCode, T1.CardName
) T0
LEFT JOIN
(
SELECT T2.CardCode, T3.CardName, SUM(T2.DocTotal) 'TotalCredits'
FROM AU.dbo.ORIN T2
INNER JOIN AU.dbo.OCRD T3 ON T3.CardCode = T2.CardCode

WHERE Year(T2.DocDate) = Year(Getdate())

GROUP BY T2.CardCode, T3.CardName
) T1

ON T0.CardCode = T1.CardCode

GROUP BY T0.CardCode, T0.CardName, (TotalSales - TotalCredits)
HAVING SUM([TotalSales] - [TotalCredits]) > '[%0]'


ORDER BY T0.CardName

Any help here will be greatly appreciated.

Kind Regards,

David

Attachments

Capture1.JPG (16.1 kB)
Capture2.JPG (19.5 kB)