Doctrine/Symfony WHERE clause for reports
I would suggest using the QueryBuilder

$em = $this-&gt;managerRegistry-&gt;getManager();
$qb = $em-&gt;createQueryBuilder()
    -&gt;select('u')
    -&gt;from(User::class, 'u')
    -&gt;join('u.meta', 'um'); // doctrine generates the join condition automatically


if (!empty($accountNumber)) {
    $qb
        -&gt;andWhere('u.accountNumber = :acc_number')
        -&gt;setParameter('acc_number', $accountNumber)
}
if (!empty($companyName)) {
    $qb
        -&gt;andWhere('u.companyName = :company_name')
        -&gt;setParameter('company_name', $companyName)
}

// and so on...

return $qb-&gt;getQuery()-&gt;getResult();