select distinct t1.Name,t1.pageStyleName from
(
select * from
(
select ff.Name,xPageStyle.value('../@Name','varchar(100)') pageStyleName, xPageStyle.value('@Token','varchar(100)') token
from Formats ff
cross apply Data.nodes('//PageStyle/Item') tPageStyle(xPageStyle)
where ff.Name like 'CWE%' or ff.Name like 'EX%'
and xPageStyle.value('@Token','varchar(100)') not like '{BOX%'
) ah
) t1
left join
(
select * from
(
select * from
(
select ff.Name,xPageStyle.value('../@Name','varchar(100)') pageStyleName, xPageStyle.value('@Token','varchar(100)') token
from Formats ff
cross apply Data.nodes('//PageStyle/Item') tPageStyle(xPageStyle)
where ff.Name like 'CWE%' or ff.Name like 'EX%'
) ah
where token like '{BOX%'
) ah
) t2 on t1.name = t2.name and t1.pagestylename = t2.pagestylename
where t2.name is null
