--取上个月的工资数据记录,导出到表#temp中
select * into #temp from gz_gz where imonth int (select max(month) from gz_gz )
--修改上个月的月份值或年度值
update #temp
set gzmonth=gzmonth+1
or 
update #temp
set gzyear=gzyear+1
--导入到工资表中
insert into gz_gz select * from #temp

解决方案 »

  1.   

    试试看,未测试。
    insert into 表 (年,月份,其它字段) select 年字段,max(月份)+1,其它字段 from 表 where 
    year(getdate()) = 年 and month(getdate()) = max(月份)
      

  2.   

    建个作业自动执行:
    select * into #tmptb from tb1 where 年月='2005-1'
    select b.fld1,b.fld2,convert(char(7),getdate(),120) into tb1 a from #tmptb b
    drop table #tmptb
    --注意,b.fld1,b.fld2,是你的表的除了 年月 字段的其它字段列表,注意字段的顺序要对应好了.
      

  3.   

    可以写一个存储过程来实现.在存储过程里边首先取得表里的最大如期并和当前日期进行比较,如果在同一个月,就返回.如果是下一个月就把上一个月的数据提取并插入到表里,并对年份和月份进行设置.把这个存储过程放到一个job里边,每个月执行一次就可以了.
      

  4.   

    To :mschen(Visual【陈】请问该存储过程如何写?
    可否给出完整的代码?