I try to use the following SQL-query to retrieve some financial information from a Dynamics NAV database to a PHP-based web appalication.
SELECT SUM([SUM$Amount]) AS total
FROM [Company Name$G_L Entry$VSIFT$1] WITH(NOEXPAND)
WHERE [Posting Date]>='2014-01-01' AND
[Posting Date]<='2014-11-26' AND
[G_L Account No_]='3020'
The query works fine when used directly in SQL Server Management Studio, but it fails when I use it in the web application though PHP PDO. I get the following error:
Array (
[0] => HY000
[1] => 1934
[2] => General SQL Server error: Check messages from the SQL Server [1934] (severity 16) [SELECT SUM([SUM$Amount]) AS total FROM [Company Name$VSIFT$1] WITH(NOEXPAND) WHERE [Posting Date]>='2014-01-01' AND [Posting Date]<='2014-11-26' AND [G_L Account No_]='3020']
[3] => -1
[4] => 16
)
I find no further error information in the server logs.
The problem is with the "WITH(NOEXPAND)"-part of the query. If I remove that, the query runs also when called from PHP. But the query then becomes very much slower as it doesn't utilize the indexed view on the table.
Does anyone know what is the problem here?