Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can this be faster
Message
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2014
Application:
Desktop
Miscellaneous
Thread ID:
01626554
Message ID:
01626615
Views:
61
>>Try
>>
>>SELECT SI.AccountCode, MAX(SI.InvoiceDate) AS Latest  
>>	FROM SalesInvoiceItem IV 
>>		INNER JOIN SalesInvoice SI ON IV.InvoiceNumber = SI.InvoiceNumber
>>	WHERE ProductCode='56.GTR003.001.01' AND MAX(SI.InvoiceDate) < DATEADD(MONTH, - 1,GETDATE())
>>GROUP BY SI.AccountCode
>>
>>
>
>Sergey, you can't use MAX in a WHERE clause. Only in a HAVING, or within context of a subquery. (And I see Naomi just posted the same thing)
>
> Do you test code before posting it? :)

So replace WHERE with HAVING. What is a big deal?
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform