Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Is it possible to bind a value for ISDESCENDANTNODE in a SQL2 query?

Avatar

Level 7

Hi,

Neither of these queries compile:

SELECT * FROM [cq:PageContent] AS n WHERE ISDESCENDANTNODE(n, [$sitePath])

SELECT * FROM [cq:PageContent] AS n WHERE ISDESCENDANTNODE(n, $sitePath)

Am I missing something here?

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 9

This statement is a string, you may have to perform string operations

statement =" SELECT * FROM [cq:PageContent] AS n WHERE ISDESCENDANTNODE(n, " + $sitePath + ")";

you need to replace $sitePath with your variable.

View solution in original post

3 Replies

Avatar

Correct answer by
Level 9

This statement is a string, you may have to perform string operations

statement =" SELECT * FROM [cq:PageContent] AS n WHERE ISDESCENDANTNODE(n, " + $sitePath + ")";

you need to replace $sitePath with your variable.

Avatar

Level 9

Maybe you can do like this

String expression = "SELECT * FROM [cq:PageContent] AS n WHERE ISDESCENDANTNODE(n, $sitePath)";  // as aboveString sitePath= ...QueryManager queryMgr = session.getWorkspace().getQueryManager();Query query = queryMgr.createQuery(expression,Query.JCR_SQL2);query.bindValue("sitePath",sitePath);QueryResult result = query.execute();