Using a Variable in a Query

1
0
-1

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!!

2 answers

1
0
-1

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.

1
0
-1

"Switch editor..."
Pencil
Script

return "select veg_cat_code from geo_feat where geo_feat_id ="+ variableToBeQueriedWith;

Comments

Submitted by alafrenz on Tue, 09/13/2016 - 17:28

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

Submitted by Sean McP on Tue, 09/13/2016 - 20:34

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

Notifications