DBA_Learner (10/20/2014)
Thanks John and Jack for your information.But, this is what the O/P i am expecting....TO GET 4th column with difference in growth from datafilesize column...
name DataFileSizeGB LogFileSizeGBDatalogged Growth Increase_MB
AdventureWorks2012 0.2001953125000.0007324218752014-10-20 13:33:40.473 0
AdventureWorksDW2012 0.1965332031250.0007324218752014-10-20 13:33:40.473 0
msdb 0.0179443359370.0255737304682014-10-20 13:33:40.473 0
tempdb 0.0078125000000.0004882812502014-10-20 13:33:40.473 0
ReportServer 0.0049438476560.0067138671872014-10-20 13:33:40.473 0
AdventureWorks2012 0.4001953125000.0007324218752014-10-21 13:33:40.473 20
AdventureWorksDW2012 0.2965332031250.0007324218752014-10-21 13:33:40.473 10
msdb 0.0179443359370.0255737304682014-10-21 13:33:40.473
tempdb 0.0078125000000.0004882812502014-10-21 13:33:40.473
ReportServer 0.0049438476560.0067138671872014-10-21 13:33:40.473
John did try to lead you there. I'm trying to give you what I think is a better way to measure what you are trying to measure. In a properly managed SQL Server, database files should never grow automatically, the DBA should be monitoring the space used and free space in database files and manually grow the files during a maintenance window or low usage time before an autogrow needs to happen. The scripts I provided can help you monitor space used and free space AND show you how much database files have grown when autogrows take place.
Here's the code John was trying to lead you to:
WITH dbSizes AS
(
SELECT
*, /* replace this with your desired column list */
/* ordering DESC means the most recent row will be 1 */
ROW_NUMBER() OVER (PARTITION BY name ORDER BY DataLogged DESC) AS rowNo
FROM
databaseSizes
)
SELECT
*, /* replace this with your desired column list */
(A.DataFileSizeGB - B.DataFileSizeGB)/1024.0 AS DataFileSizeChangeInMB,
(A.LogFileSizeGB - B.LogFileSizeGB)/1024.0 AS LogFileSizeChangeInMB
FROM
dbSizes AS A
LEFT JOIN dbSizes AS B
ON A.name = B.name AND
/* A has the most recent row (1) so it needs to be B - 1 to match */
A.rowNo = B.rowNo - 1
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question