select dbo.ve_GetShortPathFromContentId(contentid) location, * from (
select contentid, text, tt.*,
case when text like '%'+ case when tt.toid = tt.rangeid and tt.IsRange = 0
then 
'#Link:Transition:' + cast(TranType as nvarchar(2)) + 
' ' + cast(TransitionID as nvarchar(10)) + ' ' + cast(ToID as nvarchar(10)) + '%' 
else
'#Link:TransitionRange:' + cast(TranType as nvarchar(2)) + 
' ' + cast(TransitionID as nvarchar(10)) + ' ' + cast(ToID as nvarchar(10)) + ' ' + cast(RangeID as nvarchar(10))+ '%' 
end then 'matches' else 'different' end ContentMatchesTrans, 
case when text like '%'+ 
'#Link:TransitionRange:' + cast(TranType as nvarchar(2)) + 
' ' + cast(TransitionID as nvarchar(10)) + ' ' + cast(ToID as nvarchar(10)) + ' ' + cast(RangeID as nvarchar(10))+ '%' 
then 'matches' else 'different' end ContentMatchesRangeTrans
from Contents cc
join transitions tt on tt.fromid = cc.contentid) mm
where ContentMatchesTrans = 'different'