方法有两种,主要看需求。

方法1:定义好临时表的字段和类型、插入对应的值

create table #Tmp --创建临时表#Tmp
(
    City   varchar(50),  --
    Country  varchar(50),   --
);

insert #Tmp
select '北京','中国' union
select '东京','日本' union
select '纽约','美国' 

select * from #Tmp;

sql插入临时表数据的方法

 

方法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

sql插入临时表数据的方法

 

 欢迎顶....

相关文章:

  • 2021-08-20
  • 2022-12-23
  • 2022-01-10
  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2021-10-16
  • 2022-12-23
  • 2021-11-25
相关资源
相似解决方案