select contentid, printHdr, type, dbo.ve_getshortpathfromcontentid(contentid) from ( select contentid, Number, Type, isnull(xSection.value('@PrintHdr', 'varchar(255)'),'Y') printHdr from ( select cast(config as xml) xconfig, * from contents where type between 10000 and 19999 and contentid in (select contentid from parts where fromtype = 2) --and contentid in (12859, 12995) ) sectp outer apply xconfig.nodes('//Section') tSection(xSection)) kr where printHdr='N'