Maybe not the answer you want to hear, but in my opinion you're better off doing this manually. I don't think that a tool that could do this sort of things reliably would be available for free, but I would be willing to try if someone has a recommendation.
Its a complext way to supporting the multiple queries, using SSMS you can do to some extent but nothig is free when you need something critical . Why do you need to this BTW?