Developing select statement using a string

Hi ,

Can anyone please help me on this ?

How can we develop a select statement using a string?

For example I have the string as

str s = "select inventtable where inventtable.ItemId == “someid” "

Now using this string s, I have to retrieve that record from inventtable. I will just have string based on which I have to develop a select statement and retrieve the records based on this select statement

Thanks

Why do you need this? This is not a good practice when coding in DAX. Why can’t you use select statements or Query objects?

you didnt mention the problem…

expand your question by writing the purpose…why do you wanna do like this…

and its not a best practice…

My select statement will be changed based on the parameters that I select in a form.

I have around 5 Yes/No fields in a form , and these 5 Yes/No fields are associated to other 5 string fields. So I have to write a statemnt based on the Yes/No values that I select.

For example my Yes/No fields are Field1,field2,filed2,field3,field4,field5 and the string fields are field11,field22,field33,field44,field5. And now if field1 , field3 , fiel5 are set to Yes my statement should be as

"while select table1 group by field11,fild33,field55 "

So based on the yes/no values that I select my grouping changes,I cannot keep on putting multiple if-elseif conditions for each combination of the values.

Thanks

You have the Query framework exactly for this purpose.

See QueryBuildDataSource.addGroupByField() and so on.

My issue is not just grouping alone. I want to have the statament so that I can even modify that record ; i.e if I can frame a select stament I can

update that record.

Query framework supports updating too.

Although you cannot update groupped records, of course.

Could yoiu please provide equivalent query for the following statemnt

" while select sum(Amount1),sum(Amount2) from table1 group by field11,fild33,field55 where table1.field22== “someid” "

and the summing of amount1 and amount2 fields will also be based on some condition

Thanks

hi,

You can use Query, QueryRun, QueryBuildDataSource and QueryBuildRange object to prepare your query.

  1. Initialize Query object and assign a datasource to it.

query = new Query();
dsInventDim = query.addDataSource(tableNum(InventDim), tableStr(InventDim));

  1. Add a range to the object on a specific field and assing the condition to it.

queryBuildRange1 = dsInventDim.addRange(fieldNum(InventDim,DataAreaId));

queryBuildRange1.value(strFmt(’(InventSiteId == “%1”)’, queryValue(wmsiteCodesMapping.AXSiteId)));

  1. Initialize the QueryRun object and execute.

qr = new QueryRun(query);
while(qr.next())
{
if (qr.changed(tableNum(InventDim)))
{
_inventDim = qr.get(tableNum(InventDim));
break;
}
}

Hope it helps.

Regards,

/Ashlesh

Thanks for the syntax