Hi guys,
I recently started getting an error when using QueryTools.ExecuteQuery with MsSql2008FeatureLayers. It only happens when the MsSql2008FeatureLayer has a WHERE clause already applied and when you try to execute a query with ORDER BY. I suspect other combinations may also cause a problem.
Here is an example of what I mean. Say I have a spatial table called STATE and I create an instance of a MsSql2008FeatureLayer and add a WHERE clause, 'WHERE SurveySyst = 1'. Next, I attempt to use the QueryTools to execute a query, 'SELECT StateID FROM STATE ORDER BY StateID'. When I try to execute the query I get an error: 'Incorrect syntax near the keyword 'AND'.
The SQL script that actually gets sent to the server appears below:
SELECT StateID FROM vw_States WHERE StateID IS NOT NULL ORDER BY StateID AND SURVEYSYST = 1;
You can clearly see the error that occurs as the framework attempts to include the original Where cluse with the query being executed. I am working around this issue by removing the Where clause, executing the query, then re-setting the Where clause. I am using the Development build of MS, 6.0.267.0. I have attached a sample project if you need it.
Thanks,
Steve
SqlServerExecuteQuery.zip (17.2 KB)