Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

LinearGradient
Level 7
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
Mshajiahmed
Correct answer by
Level 8
Level 8

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
Mshajiahmed
Correct answer by
Level 8
Level 8

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

Mshajiahmed
Level 8
Level 8

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();