Afternoon good people of Stack Overflow.
I am trying to do something that I am not certain how to achieve with my SQL knowledge, but I have a clear idea what it is I want out of this so hopefully this will make sense to people.
I have some perfmon disk results that look like this:
DatabaseName ObjectName CounterName InstanceName Server Average
DAG1DB01 logicaldisk avg. disk sec/read d:\mountpoints\DAG1DB01 Server1 13.616
DAG1DB01 logicaldisk avg. disk sec/read d:\mountpoints\DAG1DB01 Server2 17.508
DAG1DB01 logicaldisk avg. disk sec/read d:\mountpoints\DAG1DB01 Server3 12.775
DAG1DB01 logicaldisk avg. disk sec/read d:\mountpoints\DAG1DB01 Server4 13.148
DAG1DB01 logicaldisk avg. disk sec/read d:\mountpoints\DAG1DB01 Server5 10.091
These are example rows based on this query:
SELECT
e14_db.DatabaseName AS [DatabaseName],
d.ObjectName,
d.CounterName,
d.InstanceName,
d.Server,
AVG(Value) * 1000 AS [Average]
FROM E14_Perfmon_MBX AS d
INNER JOIN E14_Databases AS e14_db
ON e14_db.LogFolderPath = d.InstanceName
WHERE d.ObjectName = 'logicaldisk'
AND d.CounterName = 'avg. disk sec/read'
AND d.DateTime > (DATEADD(hh, -4, GETDATE()))
AND d.Value < 1
GROUP BY d.ObjectName, d.CounterName, d.InstanceName, d.Server, e14_db.DatabaseName
ORDER BY e14_db.DatabaseName, d.Server
What I want is this:
DatabaseName ObjectName CounterName InstanceName Server1 Server2 Server3 Server4 Server5
DAG1DB01 logicaldisk avg. disk sec/read d:\mountpoints\DAG1DB01 13.616 17.508 12.775 13.148 10.091
Does anyone know how I can achieve this? basically applying the rows onto themselves?
If any clarification is needed please feel free to ask.
Thanks!
The following statement calculates separate averages for each server in a fixed number of columns (from 1 to 5):
You can use
PIVOTas well, but this syntax is supported by a broader range of SQL flavors.