How to SELECT * INTO [tmp table] without declare table?
i want use select statement on the a table and inserting result into a temp table variable, but i don't dec开发者_运维知识库lare 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
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.
精彩评论