The problem is that:
In SQL Server,I have a SELECT statement that might take any form like
SELECT ID,Name
FROM Table1;
Or
SELECT ID,Name
FROM Table1
WHERE ID IN(
SELECT ID
FROM Table2
WHERE City = 'C1'
)
or
SELECT *
FROM
(
SELECT ID,Name
FROM Tablex
INTERSECT
SELECT ID,Name
FROM Tablex
) AS T
or whatever sql statement that might be very complex, and I need to generate the CREATE TABLE statement that creates a table with a structure that can hold the data of the result set returned by the SELECT statement.
The code can be C# or T-SQL.
EDIT:
The SELECT statement is a parameter passed to my application.The SELECT statement usually returns millions of records that will be transferred from a server to another so I need the CREATE TABLE script to be executed on the destination server to which the data will be transferred.
Here is my try inspired from the comments on my question, and many thanks to everybody: