You’re getting the exception with the where clause, because, you have a )
with no coresponding (
.
That being said, I would probably just return the entire row for @localID
and then filter it with a lookup. Either expression or Script.
Alternatively, the “supported” way to do this (which is also discouraged) would be to create a query string parameter in the named query.
Generally if you think you need dynamic sql, you should probably take a step back and make sure that the risks you are taking are really worth it and there isn’t another way to achieve the goal the gets you the same or similar results without the risk.