Using a Variable in a Query

Hello all,

I have been attempting to insert a variable into a query and have found many different posts around the internet telling me to do it many different ways. For example… if I had the query

select veg_cat_code from geo_feat where geo_feat_id = ‘5’;

I want to have it be

select veg_cat_code from geo_feat where geo_feat_id = ‘variableToBeQueriedWith’;

I can’t seem to find out how to do this. I’ve read that

select veg_cat_code from geo_feat where geo_feat_id = ‘${variableToBeQueriedWith}’;

would work but it gives me an error. Any and all help is much appreciated!!

“Switch editor…”
Pencil
Script

return “select veg_cat_code from geo_feat where geo_feat_id =”+ variableToBeQueriedWith;

Would you please tell where to write the query in the script?
I only know to write the query in BDM custom queries but that does not provide the dynamic query.
Also, I want to write the dynamic query at runtime.
P.S: I can not write in comments, for now, they are disabled.

PERFECT! Would I have to do anything different to use a business variable in it?

When you say Business Variable are you referring to a BDM?

If so then you could do this:

return "select veg_cat_code from geo_feat where geo_feat_id ="+ BDM.getItemID();

Note that the example is for NUMERIC data. For String data you would need something like:

return "select veg_cat_code from geo_feat where geo_feat_Text ='"+ BDM.getItemText()+ "'";

regards