Replacing "]" with empty string will still have an issue for following set of data. And also you are not replacing the text in PATINDEX's data parameter.
Sample data:
declare @t table(data varchar(20))
insert into @t
select '9999999999999' union all
select '] ' union all
select ']]]]]]]]]]]]]]'
select data from @t
where PATINDEX('%[^'+left(replace(data,']',''),1)+']%',data)=0
Resolution:
Try replacing it with char(0) or any other non printable character.
select data from @t
where PATINDEX('%[^'+left(replace(data,']',char(0)),1)+']%',replace(data,']',char(0)))=0
commented on Feb 24 2011 4:40AM