Technical Article

Script to determine if all chars are same in field

,

This script is actually based on a script by epol29.  That was titled 'Script to count the number of Yes/No in the string', which I found to be an awsome script.

Anyway, this script uses the same logic to deterimine if all of the characters in a field are the same.  For example, 1111111, aaaaaaaa, 4444, 22, 77777.

It works by replacing all chars by that match the first char with a blank.  If all chars are replaced, you are left with a zero length result.  So, all you have to do is check to see if the length is 0, if it is, then true, else false.

Hope this helps someone.

Declare @repeat char(255)
set @repeat = 'bbbbbbb'

select case when len( REPLACE(@repeat,substring @repeat,1,1),'')) = 0 then 'True' else 'False' end as Repeat

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating