I get the following error in the dataset when I open the template in designer mode or the form using the template is opened in user mode. The dataset uses a custom property in the where clause for ScaleNo. The custom property isn’t populated before the dataset query is run and that causes the SQL syntax error.
Error running query: SQLQuery(query=SELECT RunNo , VarietyName , LEFT(BlockID, 4) AS LotNo , BlockName AS LotName , GradeName , SizeName , ProductType FROM TrnQcifyScaleConfig WHERE PacklineName = '' AND ScaleNo = AND ActiveConfigYN = 'Y', database=)@30000ms On: tQcifyData.tQcifyData.dsCurrLot
Here is the dataset SQL query:
SELECT RunNo , VarietyName , LEFT(BlockID, 4) AS LotNo , BlockName AS LotName , GradeName , SizeName , ProductType FROM TrnQcifyScaleConfig WHERE PacklineName = '{tQcifyData.PacklineName1}' AND ScaleNo = {tQcifyData.ScaleNo1} AND ActiveConfigYN = 'Y'
Is there any way to delay updating this query until the integer custom property ScaleNo1 is populated? Or is there some syntax in the SQL that would convert the blank value to zero (ISNULL still throws an error due to invalid syntax)? Or anything else to prevent this error when the window is opened? It causes the screen to turn pink when the window is opened, it quickly clears, but makes the user feel like there is something wrong.
Tip: rather than format each line of code individually, select the whole block and use the </> button. It gives syntax highlighting too. Please see Wiki - how to post code on this forum.
The problem is not with the alpha field, it is with the ScaleNo1 custom property field. It evaluates to blank and even with COALESCE (like with ISNULL) it gives a syntax error.
SQLQuery(query=SELECT RunNo , VarietyName , LEFT(BlockID, 4) AS LotNo , BlockName AS LotName , GradeName , SizeName , ProductType FROM TrnQcifyScaleConfig WHERE PacklineName = '' **AND ScaleNo = COALESCE(, 0) AND** ActiveConfigYN = 'Y', database=)@30000ms On: tQcifyData.tQcifyData.dsCurrLot
It works without the error using the named query and passing the properties to the named query. Thanks for steering me in the right direction, this issue has been resolved.