select m.fspro_userId, m.firstName, m.lastName, m.email, m.firstName + ' ' + m.lastName as fullName, m.lastName + ', ' + m.firstName as lastFirst
from tbl_fspro_members m with (nolock)
where (( m.ownerId = and m.fsl_tablecode = )
or ( m.fsl_tablecode = 'BRO' and m.ownerId > 0 )
)
and ( exists ( select * from tbl_OPR_ClientOperators opr with (nolock)
where opr.mfr_bsr_id = m.fspro_userId
and opr.ownerId = and opr.fsltablecode = )
or exists ( select * from tbl_CDR_Distributors cdr with (nolock)
where cdr.mfr_bsr_id = m.fspro_userId
and cdr.ownerId = and cdr.fsl_tablecode = )
)
order by m.lastName, m.firstName
for json auto, include_null_values