declare @now datetime
set @now=getdate()insert into f2 select val,max(DateAndTime) DateAndTime from f1 a where datediff(day,DateAndTime,@now)=1
and exists(
select 1 from f1
where datediff(day,DateAndTime,@now)=1
group by datepart(hh,DateAndTime)
having datepart(hh,DateAndTime)=datepart(hh,a.DateAndTime) and max(val)=a.val
)
group by val,datepart(hh,DateAndTime)
服务器: 消息 213,级别 16,状态 4,行 4
插入错误: 列名或所提供值的数目与表定义不匹配。
数据类型都一样val float,dateandtime datetime

解决方案 »

  1.   

    insert into f2 
    (字段名,字段名2 ....)
    select val,max(DateAndTime) DateAndTime from f1 a where datediff(day,DateAndTime,@now)=1
    and exists(
    select 1 from f1
    where datediff(day,DateAndTime,@now)=1
    group by datepart(hh,DateAndTime)
    having datepart(hh,DateAndTime)=datepart(hh,a.DateAndTime) and max(val)=a.val
    )
    group by val,datepart(hh,DateAndTime)
      

  2.   

    insert into f2 (c1,c2..)
      select c1,c2..
    要一一對應
      

  3.   

    完全一样?
    1 select * into t2 from t1
    2 insert t1 select * from t2
      

  4.   

    dawugui(潇洒老乌龟) 
    你没有见到还有条件?
      

  5.   


    insert into f2 (列名1,列名2)楼主试一下这种方法。看下插入数据的列与f2表列的对应
      

  6.   

    完全一样?
    1 select * into t2 from t1 where ...........
    2 insert t1 select * from t2 where.........
      

  7.   

    declare @now datetime
    set @now=getdate()insert into f2 (val,DateAndTime)
    select val,max(DateAndTime) DateAndTime from f1 a where datediff(day,DateAndTime,@now)=1
    and exists(
    select 1 from f1
    where datediff(day,DateAndTime,@now)=1
    group by datepart(hh,DateAndTime)
    having datepart(hh,DateAndTime)=datepart(hh,a.DateAndTime) and max(val)=a.val
    )
    group by val,datepart(hh,DateAndTime)闷死啦,看见希望啦,可是就是写不进去
    (所影响的行数为 0 行)
      

  8.   

    是不是你 符合你where条件的没有数据啊
      

  9.   

    将其字段对应看看insert into Table1(ColName1,ColName2)select ColName1,ColName2s from table2