i want use select statement on the a table and inserting result into a temp table variable, but i don't declare temp table with columns and i want use like this:
Declare #tmp table; SELECT * INTO #tmp FROM myTable
this want declare columns and data types for #tmp
please help me
INSERT INTO SELECT statement reads data from one table and inserts it into an existing table. Such as, if we want to copy the Location table data into a temp table using the INSERT INTO SELECT statement, we have to specify the temporary table explicitly and then insert the data.
#table refers to a local temporary table - visible to only the user who created it. ##table refers to a global temporary table - visible to all users.
You can do this simply without the DECLARE command - which is not valid for #temp tables anyway, only @table variables. Did you try just the following without trying to define #tmp first:
SELECT * INTO #tmp FROM myTable;
With data:
select * into #tmp from myTable
No data:
select * into #tmp from myTable where 0=1
BTW, you can not do this with table variables.
select * into @tmp from myTable
Table variables need to be declared with the columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With