I'm a total nit sometimes. The query wasn't working because I assigned the @sql variable as varchar(255) but the string was over 255 characters. Once I increased the amount of characters, the whole string was being read into the variable. Now it works
