SQL Agetnt定时备份与定时执行存储过程

计划备份:

DECLARE @strPath NVARCHAR(200)
set @strPath = convert(NVARCHAR(19),getdate(),23)
set @strPath = REPLACE(@strPath, ':' , '.')
set @strPath = 'E:\Backup\' + @strPath +'备份'+ '.bak'
BACKUP DATABASE [jewelry] TO DISK = @strPath WITH NOINIT , NOUNLOAD , NOSKIP , STATS = 10, NOFORMAT

 

计划存储过程:

EXEC HRAttendsum_update;

exec HRAttend_UpFromFlow_absent;
exec HRAttend_UpFromFlow_AttCard;
exec HRAttend_UpFromFlow_business;
exec HRAttend_UpFromFlow_mobile;
exec HRAttend_UpFromFlow_overtime;
exec HRAttend_UpFromFlow;

sql存储过程:

USE [HRData]
GO
/****** Object:  StoredProcedure [dbo].[HRAttendsum_insert]    Script Date: 08/25/2022 10:23:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

--每天0点执行当天数据的写入
ALTER proc [dbo].[HRAttendsum_insert]
 as    
-- if(@FDate ='')
 declare @FDate varchar(10)
   set @FDate=Convert(nvarchar(10),GETDATE(),23)
 insert into HRAttendsum (userid,username,Fdate,department,seclevel)
 select loginid,lastname,@FDate,departmentid,a.seclevel from EDATA.dbo.hrmresource
 a left join  HRAttendsum hh on hh.userid=a.loginid and hh.Fdate=@FDate
 where hh.userid is null and (loginid like '8888%' or loginid='8000')
 
 --更新用户级别
 update a set  a.seclevel=b.seclevel from HRAttendsum a 
 left join EDATA.dbo.hrmresource b on b.loginid=a.userid
 --更新日期类别
update dbo.HRAttendsum set day_type=bb.daytype from HRAttendsum
left join (
select a.fdate,a.day_type,
 case when b.IsWork=1 and HolidayType=0 then 0
   when b.IsWork=0 and HolidayType=0 then 1
    when b.IsWork=0 and HolidayType=1 then 2
   else 3 End AS 'daytype'
  from HRAttendsum a
 left join dbo.HRWorkDay b on b.FDate=a.FDate)
  bb on bb.FDate=HRAttendsum.Fdate
 
--select * from   HRAttendsum set seclevel=0    Fdate=Convert(nvarchar(10),GETDATE(),23)
 --更新日期类别
 update HRAttendsum set remarks='节假日' from HRAttendsum 
where Day_Type=0 and EndTime is null and StartTime is null 
and Fdate>'2016-12-31'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jekc868

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值