cancel
Showing results for 
Search instead for 
Did you mean: 

Need formula help - query on characters in a text field

Former Member
0 Kudos

Post Author: bemmerich

CA Forum: General Feedback

In the database, phone numbers are stored as text, not numbers. Example 123-456-7890

How do I query so that I choose only phone numbers in the format where the 4th character is a dash and the 8th character is a dash?

This will exclude foreign phone numbers, which is my goal.

Thank you!

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Post Author: jsanzone

CA Forum: General Feedback

Bemmerich,

what reporting tool are your working in? If it is WebI, then when you build a query, in your Query Filters section where you bring the object over and want to use as a filter, choose from the drop-down selector next to "Equal to" and find the option "Matches pattern", then in the next field manually type ___-___-____ and voila you will be able to filter properly on US-type phone numbers. The "Matches pattern" method translates to the "like" capability in SQL. The underscore (_) is the single wild card character, so using three underscores followed by a dash, followed by three more underscores, dash, and followed by four more underscores tells SQL to consider the fourth and 8th character positions where both are a dash.

If you're using other tools like Crystal or Designer, then you may be able to use actual SQL coding and thus can employ the substring capability, which IMHO is more efficient in terms of machine execution, etc, etc. For instance: where substring(phone_no,4,1)='-' and substring(phone_no,8,1)='-'