Skip to Content
0
Jul 10, 2020 at 12:31 AM

SAP CAP - How to do Join

2303 Views

Hello Everyone,

I am trying to join two tables/entities using NodeJS as a language.

I got below mentioned error

I tried the solution mentioned in the following URLs

https://answers.sap.com/questions/13038904/how-to-performing-a-join-using-cqn-using-fluid-nod.html

https://answers.sap.com/questions/13006576/cap-cds-nodejs-create-dynamic-join-in-custom-logic.html

It works only when I hardcoded the full table name. But when I try to pass the variable, it is not working

Below is the code which is not working ( Here I am passing variables)

const db = await cds.connect.to('db')
const { tableA, tableB} = db.entities('namespace')
 let query = SELECT.from(tableA)
                    .join(tableB)
                    .on('tableA.ID','=','tableB.ID')
let results = await cds.run(query)

Below is the code which is working ( Here I am passing full table name instead of variable)

 let query = SELECT.from('namespace.tableA')
                    .join('namespace.tableB')
                    .on('namespace.tableA.ID','=','namespace.tableB.ID')
let results = await cds.run(query)

Kindly advise

Regards,

Sandeep

Attachments

join-error.png (41.0 kB)