with due respect, you are a novice, you're generating dynamic SQL in code rather than creating a query and passing parameters to it which would at least let you debug your SQL independently from your code and vice versa and, when it comes to passing those parameters, identify more explicitly...