Creating a search query with wildcard in SQL2

Reporter

I've got a request about a search, using wildcard.

I created the following query

SELECT * FROM [nt:base] AS p WHERE
ISDESCENDANTNODE(p, [/home/users/ldap/2]) AND
p.[sling:resourceType] = 'cq/security/components/profile' AND 
Contains (p.memberOf, 'SUG-pilot-anna')

and it works as expected. The task of this query is to look for users, who are member of a particular ldap group.

Because there is a lot of work to search for every single group, like

SUG-pilot-anna
SUG-pilot-berta
SUG-pilot-ceta

, it would be easier and more efficient to use the wildcard. According serveral documantations, the LIKE operator is supported by SQL2.

My question is: how does looks the query with wildcard?

Thanks for your help/idears.

rakhi4110

You can use the % wildcard and query for your requirements.

SELECT * FROM [nt:base] AS p WHERE
ISDESCENDANTNODE(p, [/home/users/ldap/2]) AND
p.[sling:resourceType] = 'cq/security/components/profile' AND 
p.memberOf LIKE 'SUG-pilot-%'

This would return the list of users who belong to any group name starting with SUG-pilot-. '%' matches zero or more characters and '_' matches exactly one character.

The exact query which was working in my instance was

SELECT * FROM [nt:base] AS p WHERE
ISDESCENDANTNODE(p, [/home/users/]) AND
p.[sling:resourceType] = 'cq/security/components/profile' AND 
p.memberOf LIKE '%de%'

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Creating advanced search query with PHP Mysqli

分類Dev

SQL Query for a search function

分類Dev

sql search query with like operator

分類Dev

SQL query search within a string

分類Dev

Hibernate search - cconvert sql to lucene query

分類Dev

SQL Query to do a reverse CONTAINS search?

分類Dev

SQL search query with dynamically build where condition

分類Dev

Exclude directories from Windows Search by wildcard

分類Dev

How to use wildcard characters in Spotlight search?

分類Dev

Query for ANY value in complex key (AKA wildcard)

分類Dev

SQL: Using <= and >= to compare string with wildcard

分類Dev

Cannot get wildcard search working with Sphinx Real Time indexes

分類Dev

How do I search in Windows using the wildcard but only in the particular folder?

分類Dev

Search query in mongodb using AND OR

分類Dev

if search query is met function

分類Dev

Linq query to search

分類Dev

Elastic Search query filtering

分類Dev

Creating Dynamic Select Query in SqlAlchemy

分類Dev

Creating columns from a select query

分類Dev

Creating a BAT file to execute query

分類Dev

Having trouble creating a Laravel query

分類Dev

Creating a CloudWatch alarm based on a search expression

分類Dev

Creating single query with subquery, essentially a insert query with select query

分類Dev

MarkLogic combine cts:query and search:query

分類Dev

Apache2 wildcard not showing the correct DocumentRoot

分類Dev

how to query the highest digit in a search?

分類Dev

Elastic search query not returning results

分類Dev

Elastic Search Query with Java Api

分類Dev

GAE search query using date?

Related 関連記事

ホットタグ

アーカイブ