Script to determine if all chars are same in field

,

This script is a fix to the "Script to determine if all chars are same in field"
posted by Harvard Kinkead (hneal_98) .
That script doesn't handle strings with trailing spaces (e.g. set @repeat = 'bbbb ')
It happens because of the nature of Len function.
To bypass this limitation my script concatenates one character to tested string and then takes it into account in length evaluation.
If the length is 1 then true, else false.

Declare @repeat varchar(255)
set @repeat = 'bbbb  '

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

Rate

Share

Share

Rate