How to leverage JCR SQL2 Query with LIKE Operator | Community
Skip to main content
March 23, 2022
Solved

How to leverage JCR SQL2 Query with LIKE Operator

  • March 23, 2022
  • 2 replies
  • 2747 views

Hi, 

We have a situation where we are currently querying to find an Image with the below pattern
abcd_108489356_en.jpg and it is giving the results.


SELECT * FROM [dam:Asset] AS a WHERE ISDESCENDANTNODE(a,[/content/dam/some-company/creative-assets/automobiles/offers]) AND a.[jcr:path] LIKE '%/108489356_en.jpg' ORDER BY a.[jcr:created]

Sometimes images in the DAM would be something like 108489356_enfr.jpg

How can we leverage the above Query to find 108489356_enfr.jpg if 108489356_en.jpg doesn't exist? 

Thanks,

@

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Nitin_laad

@mrudulmo what about the below query?

SELECT * FROM [dam:Asset] AS a WHERE ISDESCENDANTNODE(a,[/content/dam/some-company/creative-assets/automobiles/offers]) AND a.[jcr:path] LIKE 'abcd_108489356%' ORDER BY a.[jcr:created]

2 replies

Nitin_laad
Community Advisor
Nitin_laadCommunity AdvisorAccepted solution
Community Advisor
March 23, 2022

@mrudulmo what about the below query?

SELECT * FROM [dam:Asset] AS a WHERE ISDESCENDANTNODE(a,[/content/dam/some-company/creative-assets/automobiles/offers]) AND a.[jcr:path] LIKE 'abcd_108489356%' ORDER BY a.[jcr:created]

MrudulMoAuthor
March 24, 2022

Thanks, @nitin_laad Nitin, This should work.

MrudulMoAuthor
March 28, 2022

@nitin_laad @debal_das 

Thanks for this.
Of late there is a small change in requirement. 
In DAM we would have something like this 

 

scenario 1: 1000590_en.jpg AND 1000590_fr.jpg
scenario 2: 1000590_enfr.jpg - (If this exist there will not be above, scenario 1)

And in the request, we always have either 1000590_en.jpg or 1000590_fr.jpg
How can we achieve this with a single Query, not successive Queries

DEBAL_DAS
March 24, 2022

Another approach you could use also, like operator with NAME() function as shown below -

 

 

 

MrudulMoAuthor
March 24, 2022

Thanks @debal_das Appreciate your help!