-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBackupSize_Diff.sql
More file actions
71 lines (48 loc) · 1.72 KB
/
Copy pathBackupSize_Diff.sql
File metadata and controls
71 lines (48 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use tempdb
go
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('#localtemp')
AND type = 'U')
DROP TABLE #localtemp
GO
use BackupsizeTracking
go
create table #localtemp
(
diff decimal(9,2)
, databasename varchar(100)
, ServerIP varchar(100)
)
declare @databases table
(
Id int identity(1,1)
, Name varchar(100)
, IP varchar(50)
)
INSERT INTO @databases
select distinct(chvdatabasename), chvServerIP from tbllogresult
group by chvserverip, chvdatabasename
DECLARE @RowCount INT
SET @RowCount = (SELECT COUNT(*) FROM @databases)
-- Declare an iterator
DECLARE @I INT
-- Initialize the iterator
SET @I = 1
-- Loop through the rows of a table @myTable
WHILE (@I <= @RowCount)
BEGIN
DECLARE @mindate as datetime
DECLARE @maxdate as datetime
declare @database varchar(100) = (select name from @databases where id = @I)
declare @IP varchar(50) = (Select IP from @databases where id = @I)
SET @mindate = (select min(dtmstatistics) from tbllogresult where chvDatabaseName = @database and chvServerIP = @IP)
SET @maxdate = (select max(dtmstatistics) from tbllogresult where chvDatabaseName = @database and chvServerIP = @IP)
DECLARE @minsize as decimal(9,2)
DECLARE @maxsize as decimal(9,2)
SET @minsize = (select chvDatabaseBackupSizeMB from tblLogResult where dtmStatistics = @mindate AND (chvDatabaseName = @database and chvServerIP = @IP))
SET @maxsize = (select chvDatabaseBackupSizeMB from tblLogResult where dtmStatistics = @maxdate AND (chvDatabaseName = @database and chvServerIP = @IP))
insert into #localtemp
select @maxsize - @minsize, @database, @IP
SET @I = @I + 1
END
select top 20 * From #localtemp order by diff desc
--drop table #localtemp