I want all the uppercase words from a field that has upppercase words followed by other data. Ex: HELLO There becomes HELLO. I got this far: SET @temp = SUBSTRING(@temp,1,PATINDEX('%[^A-Z ]%',@temp-1));
Can't imagine why you need this but here goes
select i,d,reverse(
substring(reverse(substring(d+' a',1,PATINDEX('%[^A-Z ]%',d+' a')))
,charindex(' ',reverse(substring(d+' a',1,PATINDEX('%[^A-Z ]%',d+' a'))))
,len(d)+2)
) t
from (
select i=
1,'Hello there' d union all select
2,'HEllo there' union all select
3,'HELLO there' union all select
4,'HELLO There' union all select
5,'HELLO THere' union all select
6,'HELLO THERE' union all select
7,'HELLO THERE fool'
) a
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.