SQLTeam.com | Weblogs | Forums

Find string that coontains double %%


#1

Hi Team,

i have multiple records in table like this:

vi%kas
vi%%kas
vi%kas
vi%%kas
vi%kas
vi%%kas

i need to find out how many records cantain single % and how many records contains double %%.

when i execute following query but it return all records that have % either one or two times.

select ename from emp
where ename like '%[%]%'

please suggest what should i do.


#2
where ename like '%[%]%' AND ename NOT like '%[%]%[%]%'

This will be 2-or-more

where ename like '%[%]%[%]%'

#3
select 
    sum(case when ename like '%[%]%' and ename not like '%[%][%]%' then 1 else 0 end) 
        as single_percent_count,
    sum(case when ename like '%[%][%]%' then 1 else 0 end) 
        as double_percent_count
from (
    values('vi%kas'),('vi%%kas'),('vi%kas'),
              ('vi%%kas'),('vi%kas'),('vi%%kas'),('vi%%kas')) as emp(ename)