- You have two query statements there. What is the relation between these two?
- Replace your "ID" parameter with "@ID", and use the parameters property of the statement object to add value. See
MSDN
- Storing result in a new table (this will create a new table):
SELECT field1, field2, field3
INTO newtable
FROM
( subquery ) as sq