embedded SQL query generation here