declare @ownerId int = ; declare @ownerType varchar(3) = ; with data as ( select fspro_userId, firstName, lastName, email, title, staffMember, loginEnabled, firstName + ' ' + lastName as fullName from tbl_FSPro_members with (nolock) where ownerId = @ownerId and fsl_tablecode = @ownerType and nullif( orgId, 0 ) is null -- make sure we we don't get CRM contacts and nullif( email, '' ) is not null -- make sure we only get those with email address and fspro_userId = and staffMember = 1 and loginEnabled = 1 ) #forJSON( 'data', attributes.dataStore, 'fullName' )# attributes.datastore.writeToLog( _r );