刚才网络有问题~~突然上不去网~ declare @i int set @i=1 while @i<14 begin select * from ( select distinct a.DataTime,b.FileName,b.SheetName, b.SheetType,b.ReportName,b.CoreReportName, a.DisplayName from a,b where a.wsObtainID=b.wsObtainID ) tg where tg.DataTime=2000+@i set @i=@i+1 end 希望把结果合并成一横行
用临时表把:if OBJECT_ID('tempdb..#temp') is not null drop table #tempselect * into #temp from ( select distinct a.DataTime,b.FileName,b.SheetName, b.SheetType,b.ReportName,b.CoreReportName, a.DisplayName from a,b where a.wsObtainID=b.wsObtainID ) tg where 1=2 declare @i int set @i=1 while @i<14 begin insert into #temp select * from ( select distinct a.DataTime,b.FileName,b.SheetName, b.SheetType,b.ReportName,b.CoreReportName, a.DisplayName from a,b where a.wsObtainID=b.wsObtainID ) tg where tg.DataTime=2000+@i set @i=@i+1 end select * from #temp
我不明白你为什么要用循环 我看你的语句直接tg.DataTime用一个范围值就可以了。select * from ( select distinct a.DataTime,b.FileName,b.SheetName, b.SheetType,b.ReportName,b.CoreReportName, a.DisplayName from a,b where a.wsObtainID=b.wsObtainID ) tg where tg.DataTime between 2001 and 2014这样不可以么?
declare @i int
set @i=1
while @i<14
begin
select * from (
select distinct a.DataTime,b.FileName,b.SheetName,
b.SheetType,b.ReportName,b.CoreReportName,
a.DisplayName
from a,b
where a.wsObtainID=b.wsObtainID
) tg
where tg.DataTime=2000+@i set @i=@i+1
end
希望把结果合并成一横行
用临时表把:if OBJECT_ID('tempdb..#temp') is not null
drop table #tempselect * into #temp from (
select distinct a.DataTime,b.FileName,b.SheetName,
b.SheetType,b.ReportName,b.CoreReportName,
a.DisplayName
from a,b
where a.wsObtainID=b.wsObtainID
) tg
where 1=2
declare @i int
set @i=1
while @i<14
begin
insert into #temp
select * from (
select distinct a.DataTime,b.FileName,b.SheetName,
b.SheetType,b.ReportName,b.CoreReportName,
a.DisplayName
from a,b
where a.wsObtainID=b.wsObtainID
) tg
where tg.DataTime=2000+@i set @i=@i+1
end
select *
from #temp
select distinct a.DataTime,b.FileName,b.SheetName,
b.SheetType,b.ReportName,b.CoreReportName,
a.DisplayName
from a,b
where a.wsObtainID=b.wsObtainID
) tg
where tg.DataTime between 2001 and 2014这样不可以么?