Everything is fine in the SP which seth has given
Only thing is i donot want to create #a like below
CREATE TABLE #a(
instead it has to do dynamic like select * into #a because the values i am inserting is like copying of different tables @ run time, so i will not be knowing the number of oculns prior.
All the work you need to do with the temp table needs to be included in the dynamic SQL.
Even if you were able to reference the temp table outside the dynamic SQL, what can you do with it without knowing the columns?
Maybe if you tell us more of your process, someone can suggest an alternative.