sql插入臨時表數據的方法


方法有兩種,主要看需求。

方法1:定義好臨時表的字段和類型、插入對應的值

create table #Tmp --創建臨時表#Tmp
(
    City   varchar(50),  --
    Country  varchar(50),   --
);

insert #Tmp
select '北京','中國' union
select '東京','日本' union
select '紐約','美國' 

select * from #Tmp;

 

方法2:直接將查詢出來的表數據插入臨時表中

if OBJECT_ID('tempdb..#temp') is not null
drop table #temp
select * into #temp from 
(
    --select * from Activity
    select 7 as 'month',25 as 'day'
    union all
    select 7 as 'month',25 as 'day'
    union all
    select 8 as 'month',25 as 'day' 
    union all
    select 8 as 'month',25 as 'day'
    union all
    select 8 as 'month',25 as 'day'
 
) as A


select *  from #temp

 

 歡迎頂....


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM