临时表的使用
declare @count3 int,@count7 int,@count int,@countMore int; select @count3=count(*) from Exam_QuesContent where DateDiff(d,addDate,getdate())<3 --最近三天 select @count7=count(*) from Exam_QuesContent where DateDiff(d,addDate,getdate())<7 --最近七天 select @count=count(*) from Exam_QuesContent where DateDiff(d,addDate,getdate())=0 --今天 select @countMore=count(*) from Exam_QuesContent --更久 if object_id('tempdb..#Tmp') is not null Begin drop table #Tmp End create table #Tmp --创建临时表#Tmp ( ID int IDENTITY(1,1) NOT NULL, --创建列ID,并且每次新增一条记录就会加1 Title text, --标题 BiaoShi varchar(50),--标示 Error int --ID字符串 ); insert #Tmp(Title,BiaoShi,Error)values('今天','today',@count); insert #Tmp(Title,BiaoShi,Error)values('最近三天','san',@count3); insert #Tmp(Title,BiaoShi,Error)values('最近七天','qi',@count7); insert #Tmp(Title,BiaoShi,Error)values('更久','more',@countMore); select * from #Tmp;