方法有兩種,主要看需求。
方法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
歡迎頂....