UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
mysql> create tb_employee(userid varchar(100),StartDate datetime,WorkedAge float);
insert into tb_employee(userID,StartDate)values('0001','2015-05-05');
---------------
create event `UpdateWorkedMonth` on schedule every 1 day starts '2016-11-01 01:10:00'
do update tb_employee set WorkedAge=TIMESTAMPDIFF(MONTH,StartDate, curdate())/12;
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
mysql> create tb_employee(userid varchar(100),StartDate datetime,WorkedAge float);
insert into tb_employee(userID,StartDate)values('0001','2015-05-05');
---------------
create event `UpdateWorkedMonth` on schedule every 1 day starts '2016-11-01 01:10:00'
do update tb_employee set WorkedAge=TIMESTAMPDIFF(MONTH,StartDate, curdate())/12;
CREATE EVENT e_test
ON SCHEDULE EVERY 1 Day
DO UPDATE position SET Exp_CAE=Exp_CAE+ round(DATEDIFF(mm,'2016-09-30',GETDATE())/12.0,2)
这样不知道为什么不对,DATEDIFF报错了,我Exp_CAE存入的是年数2.5,2016-09-30'是该员工工作年数为2.5时的时间,这样加起来就可以了吧,Exp_CAE是用计算得到的年数,并不一定是简单的减去起始时间,所以这个字段我必须存入年数
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
mysql> create tb_employee(userid varchar(100),StartDate datetime,WorkedAge float);
insert into tb_employee(userID,StartDate)values('0001','2015-05-05');
---------------
create event `UpdateWorkedMonth` on schedule every 1 day starts '2016-11-01 01:10:00'
do update tb_employee set WorkedAge=TIMESTAMPDIFF(MONTH,StartDate, curdate())/12;
CREATE EVENT test
ON SCHEDULE EVERY 1 SECOND starts '2016-10-31 15:06:00'
DO UPDATE position SET Exp_CAE=Exp_CAE+ round(TIMESTAMPDIFF(MONTH,'2016-09-30',curdate())/12.0,2)
我试了这样的,sql语句成功执行了,但是数据并没有更新啊
#13
-- drop table tab
create table tab(
id int identity(1,1),
birthDate datetime,
age as datediff(YEAR,birthDate,GETDATE()))
go
insert into tab(birthDate)
select '2001-05-15' union all
select '1969-01-11' union all
select '2000-08-01' union all
select '1988-10-25' union all
select '2012-05-12'
go
select * from tab
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
mysql> create tb_employee(userid varchar(100),StartDate datetime,WorkedAge float);
insert into tb_employee(userID,StartDate)values('0001','2015-05-05');
---------------
create event `UpdateWorkedMonth` on schedule every 1 day starts '2016-11-01 01:10:00'
do update tb_employee set WorkedAge=TIMESTAMPDIFF(MONTH,StartDate, curdate())/12;
CREATE EVENT test
ON SCHEDULE EVERY 1 SECOND starts '2016-10-31 15:06:00'
DO UPDATE position SET Exp_CAE=Exp_CAE+ round(TIMESTAMPDIFF(MONTH,'2016-09-30',curdate())/12.0,2)
我试了这样的,sql语句成功执行了,但是数据并没有更新啊
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
mysql> create tb_employee(userid varchar(100),StartDate datetime,WorkedAge float);
insert into tb_employee(userID,StartDate)values('0001','2015-05-05');
---------------
create event `UpdateWorkedMonth` on schedule every 1 day starts '2016-11-01 01:10:00'
do update tb_employee set WorkedAge=TIMESTAMPDIFF(MONTH,StartDate, curdate())/12;
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
mysql> create tb_employee(userid varchar(100),StartDate datetime,WorkedAge float);
insert into tb_employee(userID,StartDate)values('0001','2015-05-05');
---------------
create event `UpdateWorkedMonth` on schedule every 1 day starts '2016-11-01 01:10:00'
do update tb_employee set WorkedAge=TIMESTAMPDIFF(MONTH,StartDate, curdate())/12;
CREATE EVENT e_test
ON SCHEDULE EVERY 1 Day
DO UPDATE position SET Exp_CAE=Exp_CAE+ round(DATEDIFF(mm,'2016-09-30',GETDATE())/12.0,2)
这样不知道为什么不对,DATEDIFF报错了,我Exp_CAE存入的是年数2.5,2016-09-30'是该员工工作年数为2.5时的时间,这样加起来就可以了吧,Exp_CAE是用计算得到的年数,并不一定是简单的减去起始时间,所以这个字段我必须存入年数
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
mysql> create tb_employee(userid varchar(100),StartDate datetime,WorkedAge float);
insert into tb_employee(userID,StartDate)values('0001','2015-05-05');
---------------
create event `UpdateWorkedMonth` on schedule every 1 day starts '2016-11-01 01:10:00'
do update tb_employee set WorkedAge=TIMESTAMPDIFF(MONTH,StartDate, curdate())/12;
CREATE EVENT test
ON SCHEDULE EVERY 1 SECOND starts '2016-10-31 15:06:00'
DO UPDATE position SET Exp_CAE=Exp_CAE+ round(TIMESTAMPDIFF(MONTH,'2016-09-30',curdate())/12.0,2)
我试了这样的,sql语句成功执行了,但是数据并没有更新啊
#13
-- drop table tab
create table tab(
id int identity(1,1),
birthDate datetime,
age as datediff(YEAR,birthDate,GETDATE()))
go
insert into tab(birthDate)
select '2001-05-15' union all
select '1969-01-11' union all
select '2000-08-01' union all
select '1988-10-25' union all
select '2012-05-12'
go
select * from tab
UPDATE e SET e.workmonth= round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)--=1.5
FROM employee e
WHERE e.workmonth!=round(DATEDIFF(mm,'5/5/2015',GETDATE())/12.0,1)
mysql> create tb_employee(userid varchar(100),StartDate datetime,WorkedAge float);
insert into tb_employee(userID,StartDate)values('0001','2015-05-05');
---------------
create event `UpdateWorkedMonth` on schedule every 1 day starts '2016-11-01 01:10:00'
do update tb_employee set WorkedAge=TIMESTAMPDIFF(MONTH,StartDate, curdate())/12;
CREATE EVENT test
ON SCHEDULE EVERY 1 SECOND starts '2016-10-31 15:06:00'
DO UPDATE position SET Exp_CAE=Exp_CAE+ round(TIMESTAMPDIFF(MONTH,'2016-09-30',curdate())/12.0,2)
我试了这样的,sql语句成功执行了,但是数据并没有更新啊