解决方案 »

  1.   

    刚才网络有问题~~突然上不去网~
    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
    希望把结果合并成一横行
      

  2.   


    用临时表把: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
      

  3.   

    我不明白你为什么要用循环 我看你的语句直接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这样不可以么?
      

  4.   

    ~~对哦~~有datatime这玩意~~擦~~忘了~~
      

  5.   

    这个结果插入临时表,然后BAIDU一下SQL SERVER合并列值,N多。写烂了。不想写了。或者叫他们帮你写。