Firstly, with regards to dynamic SQL you are opening yourself up to SQL Injection, and the issue you are seeing is due to the lack of the space as mentioned in the other answer and comments.
But....
While you could do something like this, you are potentially going to encounter issues when you try to run it, mainly related to referential integrity.
Take this example:
User Table
UserId | Name
1 | Bob
2 | Jim
UserOrders Table
OrderId | UserId
1 | 1
2 | 1
3 | 2
4 | 2
Say you are going to delete all records in the User
table. The User
table may have related information in UserOrders
, so because the second table links to the primary key on the first table, you won't be able to delete records in the first table unless all related data is deleted, and the only way to do that is with cascade deletes, which is where this type of solution will become dangerous.
If you're only concerned about static, un-linked data, then it could work, but if there are relationships between the tables then I would advise against this type of solution.