Symptom
Error occurs when you run a query from Query Generator. However if you remove some spaces from the query, it works.
Reproducing the issue
Scenario:
- Open Query Generator from Tools → Queries.
- Click Execute to open the Query Generator window.
- Click pencil icon to change it to Edit mode.
- Copy the following query and then click Execute:
SELECT (SELECT COUNT(*) FROM WOR1 PL WHERE PL.ItemCode = I.ItemCode) AS 'TEST'
From OITM I
WHERE I.UpdateDate <= '[%0]'
Expected behavior:
Query - Selection Criteria window is opened to ask for the UpdateDate value.
Actual behavior:
Error occurs in the status bar:
1). [Microsoft][SQL Server Native Client 11.0][SQL Server]Must specify table to select from. 2). [Microsoft][SQL Server Native Client 11.0][SQL Server]Statement '' (SWEI) (s) could not be prepared.
Workaround:
If you remove the space next to the = sign in the first WHERE clause, then the query works:
SELECT (SELECT COUNT(*) FROM WOR1 PL WHERE PL.ItemCode=I.ItemCode) AS 'TEST'
From OITM I
WHERE I.UpdateDate <= '[%0]'
OR
If you remove the second WHERE clause WHERE I.UpdateDate <= '[%0]', then the query still works:
SELECT (SELECT COUNT(*) FROM WOR1 PL WHERE PL.ItemCode = I.ItemCode) AS 'TEST'
From OITM I