Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm trying to create a table on runtime, but this new table has to have the same definition as the source table.

My problem is this:
i'm importing a file to a table, but i wanto to send the file information to a temporary table and then merge with my final table.

the difficult part is that i have this mechanism very automated, and i can configure the columns that i want to send to the final table... and if someone adds columns to the new table, my process has to copy the information from the file, to the temporary table and after that send it to the final table. the temporary table isnt managed by anyone, and the process has to create the new columns.

So, my idea is to drop the temp table on the end of my process and create every time that i run my process...

i tried to run my query as ExecuteNonQuery, but i have an select on it that makes the compiler raise an error, and if i try to run as ExecuteReader i have the same problem on "select" (Incorrect syntax near the keyword 'select'.)

can anyone help on this?

BTW im using C#. this is suppose to be a windows services.
Posted
Comments
dan!sh 20-Jul-10 11:29am    
Can you post the related code?
voloda2 20-Jul-10 15:56pm    
Or the SQL command...

1 solution

Create a dyn query like below and execute
your new table will be created as per ur dynamic structure

select top 0 null as Col1,null as Col2 into [TempNewTable]
Or else

select top 0 Col1 ,Col2 into [TempNewTable] from Maintable
(this will be more appropriate if need data type proper)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900