How can I query numeric data of type String by condition? | Community
Skip to main content
ChaoXiong
New Participant
December 6, 2022
Solved

How can I query numeric data of type String by condition?

  • December 6, 2022
  • 2 replies
  • 1193 views

Dears

       As shown, if the field is set to a number of type String, how can I query the data according to the condition?

 

 

 

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 Nikita___Garg

Hi @chaoxiong ,

 

You can try using groovy script which can read the value from String property and save in long property. This will help you manipulate the content and query the field with numeric operations.

 

Thanks,

Nikita Garg

2 replies

Chandra_Hire
New Participant
December 6, 2022

Hi @chaoxiong 

 

1. Use SQL2 Query and Cast statement to convert datatypes. How to use AEM JCR SQL2 query strings to query for nodes in Java Content Repository - Sourced Code

 

2. If property storing number with minimal range e.g., maximum number is 13 then use OR operator for 13 times in query builder query (Ugly solution)

 

FYI: If you want to change the data type - How to Change Data Type in AEM or Data Typecast using @TypeHint (argildx.us)

 

Hope this helps.

 

Thanks,

Chandra

krati_garg
Employee
December 6, 2022

@chaoxiong 

If the Field is String Type, you cannot expect numeral comparison as an output for logical operators. In the end, it is being compared as a String and not a numeral.

 

I would suggest changing the Data Type of this "number" property to Long instead of String.

ChaoXiong
ChaoXiongAuthor
New Participant
December 6, 2022

Thanks @krati_garg 

Because this is an example, there is already a lot of data in the actual project that is of String type, so I hope that there are related methods to query instead of modifying its type.

Nikita___GargAccepted solution
Employee
December 7, 2022

Hi @chaoxiong ,

 

You can try using groovy script which can read the value from String property and save in long property. This will help you manipulate the content and query the field with numeric operations.

 

Thanks,

Nikita Garg