MySQL group concatenation - creation of insert statement on temp table
There is no SQL that can directly perform what you have described.  Instead...

Read that data into your programming language (PHP, Java, VB, etc) and use code to construct the statement in question.  Then execute it.

Yes, a Stored Procedure could be constructed, but that might be messier.