临时表批量处理数据的使用

//第一种创建临时表

create table #tempArea
(
    ID  int IDENTITY (1,1) not null, --创建列ID,并且每次新增一条记录就会加1
    DocCode varchar(100),
    AreaName varchar(50),
    AreaCode varchar(50),
    primary key(ID)      --定义ID为临时表#Tmp的主键 
)

 --判断是否存在临时表,存在就删除掉
 if object_id('tempdb..#tempDoccode') is not null drop table #tempDoccode
 
 --保存传进来的数据到临时表,格式''1','2','3'

 select doccode into #tempDoccode FROM Deal where doccode in('404482341','63522323','44010400')  --第二种创建临时表方法

 --获取文书号对应的违章区域
 select doccode,dbo.getAreaByDoccode(doccode) as areaName from #tempDoccode

 --删除掉临时表
 Drop Table #tempDoccode

原文地址:https://www.cnblogs.com/kavilee/p/2159389.html