2014-01-21 153 views
0

我想創建一個查詢結果,並將其導出到csv而不是像我一直在做的多個。這似乎很簡單,但我無法弄清楚。將多個查詢結果導出到一個CSV csv

SELECT 
     database_name = DB_NAME(5) 
    , log_size_mb = CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8./1024 AS DECIMAL(8,2)) 
    , row_size_mb = CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8./1024 AS DECIMAL(8,2)) 
    , total_size_mb = CAST(SUM(size) * 8./1024 AS DECIMAL(8,2)) 
FROM sys.master_files WITH(NOWAIT) 
WHERE database_id =(5) 
GROUP BY database_id 

SELECT * FROM emp select @@ROWCOUNT 

SELECT * FROM BADGE WHERE STATUS=1 select @@ROWCOUNT 
activebadges 

SELECT * FROM dbo.EVENTS select @@ROWCOUNT 
eventstotal 

SELECT * FROM FAILEDRPC select @@ROWCOUNT 
+0

到底是怎麼回事了? – csmckelvey

+0

是的SQL Server,我試圖得到一個報告,而不是35分開 – user3220704

回答

0
SELECT 
     database_name = DB_NAME(5) 
    , log_size_mb = CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8./1024 AS DECIMAL(8,2)) 
    , row_size_mb = CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8./1024 AS DECIMAL(8,2)) 
    , total_size_mb = CAST(SUM(size) * 8./1024 AS DECIMAL(8,2)) 
    , emp_count = (SELECT count(*) FROM emp) 
    , activebadges = (SELECT count(*) FROM BADGE WHERE STATUS=1) 
    , eventstotal = (SELECT count(*) FROM dbo.EVENTS) 
    , failedrpc = (SELECT COUNT(*) FROM FAILEDRPC) 
FROM sys.master_files WITH(NOWAIT) 
WHERE database_id =(5) 
GROUP BY database_id 
+0

謝謝你...完美 – user3220704