« first day (1474 days earlier)      last day (2844 days later) » 

2:09 AM
Yea, I managed to do that after quite some hours in storing data for cpu, memory and disk info for sql in separated table
However, when I tried to output the data in a table to a text file with the command
DECLARE @sql NVARCHAR(4000) = 'bcp "SELECT * FROM DISK.dbo.disk_activity" queryout "C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Log\sample.log" -S ' + @@servername + ' -T -w -r -t'
EXEC sys.xp_cmdshell @sql
It only outputs a single line of text rather than split data in rows like how it shows as a table
 
 
13 hours later…
3:15 PM
SELECT

  a.1,
  a.2,
  a.3,

  SUM(CASE WHEN b.1 = 'L' THEN b.2 ELSE 0 END) as L,
  SUM(CASE WHEN b.1 = 'M' THEN b.2 ELSE 0 END) as M,
  SUM(CASE WHEN b.1 = 'O' THEN b.2 ELSE 0 END) as O

FROM a

LEFT JOIN b ON (b.1 = a.1)

GROUP BY a.1, a.2, a.3;
How do I get the three sum() to be combined into one? I don't need three separate columns in my results, I just need the total of all 3 in a single column.
 
 
4 hours later…
7:34 PM
@Waxi wrap that whole query in brackets, call it something like X and then sum() them
Probably other ways but that should be easiest
Don't forget to move that semi-colon outside of the brackets
 
7:46 PM
Also change all 3 columns to 1?
SUM(CASE WHEN b.1 IN ('L', 'M', 'O') THEN b.2 ELSE 0 END) AS ALLTOTAL
 

« first day (1474 days earlier)      last day (2844 days later) »