I have attached a document that contains the query I've written using several CTE's. I have attempted to use a variable for the first CTE (the Agency variable) which works fine. But then I've tried to insert another variable of date range in the second CTE. Instead of pulling just records for that date range, I am getting everything.
Could someone please take a look and let me know what the problem is? I have highlighted in yellow where I want my date range to be taken from.