Announcements
Hi all,
I have2 datasources
i want to exclude all fields from datasource 2 (EcoResProduct)
just showing ItemId field in a first datasource (InventTable)
this my code
query1 = new query(); qbds = query1.addDatasource(tableNum(InventTable)); qbds.addSelectionField(fieldNum(InventTable,ItemId)); qbds1 = qbds.addDataSource(tableNum(EcoResProduct)); qbds1.relations(true); qbds1.joinMode(JoinMode::InnerJoin);
thanks for this helpfull answer
I fully agree with goshoom . Here's an example:
static void Job1(Args _args) { InventTable inventTable; ItemId itemId; Query query; QueryBuildDataSource qbsInventTable, qbsEcoResProduct; QueryRun qr; ; query = new Query(); qbsInventTable = query.addDataSource(tableNum(InventTable)); qbsInventTable.addSelectionField(fieldNum(InventTable, ItemId)); qbsEcoResProduct = qbsInventTable.addDataSource(tableNum(EcoResProduct)); qbsEcoResProduct.relations(true); qbsEcoResProduct.joinMode(JoinMode::ExistsJoin); info(query.dataSourceNo(1).toString()); //SELECT ItemId FROM InventTable(InventTable_1) //EXISTS JOIN * FROM EcoResProduct(EcoResProduct_1) // WHERE InventTable.Product = EcoResProduct.RecId qr = new QueryRun(query); while (qr.next()) { inventTable = qr.get(tableNum(InventTable)); itemId = inventTable.ItemId; } }
thank you
Please explain what exactly you want to achieve. You talk about showing fields, but you code is about a database query. These are two separate things.
You may want to select fields from database that you won't show in a form or report.
But if you know that you don't need any fields from EcoResProduct and you need this table just for some filters, don't use InnerJoin. Choose ExistsJoin instead.
André Arnaud de Cal...
294,069
Super User 2025 Season 1
Martin Dráb
232,858
Most Valuable Professional
nmaenpaa
101,158
Moderator