Is your string intended to be used as a value inside an SQL query?
Or is your string going to be the entire query?
And which SQL dialect are we talking about?
I assume that "it does not help" means that you're getting an error.
It would have been nice to report that.
In any case, what you have now will result in a loop.
I you really must, you can replace the single quotes with double quotes by: