try this,update a set a.STARTTIME=b.STARTTIME, a.ENDTIME=b.ENDTIME from [表名] a inner join (select * from [表名] where [TIME]='2014-10-13') b on a.ID=b.ID where a.[TIME]='2014-10-20'
update a set starttime=b.starttime from tablename a join (select * from tablename where time='2014-10-13') as b on a.id=b.id where a.time='2014-10-20'
update a set a.STARTTIME=b.STARTTIME, a.ENDTIME=b.ENDTIME from tablename a ,(select * from tablename where [TIME]='2014-10-13') b where a.ID=b.ID and a.[TIME]='2014-10-20'
--通过游标实现即可。declare yb cursor for select id,starttime,endtime from 表名 where time='2014-10-13' open yb fetch next from yb into @id2,@starttime2,@endtime2 while @@FETCH_STATUS=0 begin update 表名 set starttime=@starttime2,endtime=@endtime2 where id=@id2 and time='2014-10-20' fetch next from yb into @id2,@starttime2,@endtime2 end close yb deallocate yb
这个问题如果表对应好了,方法 update a set starttime=b.starttime from tablename a join (select * from tablename where time='2014-10-13') as b on a.id=b.id where a.time='2014-10-20' 是没有问题的啊,这样的问题用游标处理我还是第一次见到
set a.STARTTIME=b.STARTTIME,
a.ENDTIME=b.ENDTIME
from [表名] a
inner join (select *
from [表名]
where [TIME]='2014-10-13') b on a.ID=b.ID
where a.[TIME]='2014-10-20'
from tablename a join (select * from tablename where time='2014-10-13') as b
on a.id=b.id
where a.time='2014-10-20'
set a.STARTTIME=b.STARTTIME, a.ENDTIME=b.ENDTIME
from tablename a ,(select * from tablename where [TIME]='2014-10-13') b
where a.ID=b.ID and a.[TIME]='2014-10-20'
/* Error message: SQL script is wrong
mismatched input . expecting "EQ" */
--通过游标实现即可。declare yb cursor for select id,starttime,endtime from 表名 where time='2014-10-13'
open yb
fetch next from yb into @id2,@starttime2,@endtime2
while @@FETCH_STATUS=0
begin
update 表名 set starttime=@starttime2,endtime=@endtime2
where id=@id2 and time='2014-10-20'
fetch next from yb into @id2,@starttime2,@endtime2
end
close yb
deallocate yb
from tablename a join (select * from tablename where time='2014-10-13') as b
on a.id=b.id
where a.time='2014-10-20' 是没有问题的啊,这样的问题用游标处理我还是第一次见到