Avoid using SQL queries inside a loop (SQL) | CAST Appmarq