select fsp.ownerid, fsp.fsl_tablecode from tbl_fspro_members fsp with (nolock) inner join fsenablers.dbo.tbl_cus_websites ws with (nolock) on ws.portal_ownerid = fsp.ownerid and ws.portal_ownertype = fsp.fsl_tablecode and ( ws.portal_ownertype = 'bro' or ws.portal_ownertype = 'mfr' ) and ws.active = 'y' and ( ws.portal_ownertype <> 'bro' or ( ws.portal_ownertype = 'bro' and ws.portal_ownerid = 2661 ) or ( ws.portal_ownertype = 'bro' and ws.portal_ownerid in ( ) ) ) where fsp.email = and fsp.staffmember = 1 and fsp.ownerid > 0 select * from fsenablers.dbo.tbl_cus_websites ws with (nolock) where ws.portal_ownerid = and ws.portal_ownertype = and ( ws.portal_ownertype = 'bro' or ws.portal_ownertype = 'mfr' ) and ws.active = 'y' and ( ws.portal_ownertype = 'mfr' or ws.portal_ownerid <> 14 )