Skip to main content
August 23, 2011
Question

Dynamically search for same digits

  • August 23, 2011
  • 1 reply
  • 1909 views

I need help with the most efficient way to search for same digits in ids dynamically.

After I queried my table: select MyId from Mytable then I need to check if none of these ids consist of the same repeating digits such as 0000,1111,2222,......9999

To make it more complicated, MyId doesn't have a fix length, it can be 4 digits length or 5, 6 all the way to 9. So the search of the same digits it this ids also should also correspond to the length of the ids.

If MyId is 4 digit long, I should make sure none of the MyId contains 0000,1111,2222,33333,...all the way to 9999

Can anyone give me example on how to do this efficienly since I may deal with large records.

This topic has been closed for replies.

1 reply

Inspiring
August 23, 2011

Unless I misunderstand the question,  just do this:

where MyID <> 9999

or whatever number you don't want to match.

August 23, 2011

Dan,

I can't do that since I don't know the length of MyId. If I know MyId is always 4 digits length, then your suggestion is working

Inspiring
August 23, 2011

Questions:

1. What database server, vendor and version, are you using?

2. What is the data type of the MyId field?

If your database server supports using regular expressions in the WHERE clause you might use a pattern like (\d)\1+ to search for repeating digits.

See: http://www.regular-expressions.info/charclass.html