Friday, 15 November 2019

Device log insert

--Exec sp_hrm_Devicelog_Insert

CREATE Procedure sp_hrm_Devicelog_Insert

As
Begin
--Declare @AttDate Date = '2017-12-30'
Drop table tempLog
--Drop table tempLog1
Drop table tempLog2

Declare @Str As Varchar(100)
Set @Str =  ('Select * into tempLog From '+ 'App91.dbo.DeviceLogs_'+ CONVERT(VARCHAR(10), Month(GETDATE() ))+'_'+CONVERT(VARCHAR(10), YEAR(GETDATE() ))  + ' order by logdate')
Exec (@Str)

--Set @Str =  ('Select * into tempLog1 From '+ 'App91.dbo.DeviceLogs_'+ CONVERT(VARCHAR(10), Month(DATEADD(DD,1,GETDATE()) ))+'_'+CONVERT(VARCHAR(10), YEAR(DATEADD(DD,1, GETDATE() )))  + ' order by logdate')
--Exec (@Str)

Set @Str =  ('Select * into tempLog2 From '+ 'App91.dbo.DeviceLogs_'+ CONVERT(VARCHAR(10), Month(DATEADD(DD,-1,GETDATE()) ))+'_'+CONVERT(VARCHAR(10), YEAR(DATEADD(DD,-1, GETDATE() )))  + ' order by logdate')
Exec (@Str)

insert into sandfitsetime.dbo.DeviceLogs ( DownloadDate,DeviceId,UserId,LogDate,C1 )

select distinct M.* from (
select GETDATE() DownloadDate,deviceid DeviceId,userid UserId,logdate Logdate,c1 c1 from tempLog a with(Nolock)
where LogDate Not In (select LogDate from sandfitsetime.dbo.DeviceLogs with(Nolock)  where UserId = a.UserId)
--Union All
--select GETDATE(),deviceid,userid,logdate,c1 from tempLog1 a
--where LogDate Not In (select LogDate from sandfitsetime.dbo.DeviceLogs where UserId = a.UserId)
Union All
select GETDATE(),deviceid,userid,logdate,c1 from tempLog2 a with(Nolock)
where LogDate Not In (select LogDate from sandfitsetime.dbo.DeviceLogs with(Nolock) where UserId = a.UserId)
  ) M
 order by m.LogDate
End





No comments:

Post a Comment