EXEC master..xp_cmdshell 'dir c:'
EXEC master..xp_cmdshell 'RENAME E:\"HR Reports"\"Master Sheet"*.xls "Master Sheet".xls'
Aug 8, 2010
T-SQL RollUp
--Sample Script
SELECT CASE WHEN (GROUPING(Data_type) = 1) THEN 'ALL'
ELSE ISNULL(Data_type, 'UNKNOWN')
END AS Data_type,
SUM(Type_id) AS Type_idSum
FROM Staging.Data_Type
GROUP BY Data_type WITH ROLLUP
SELECT CASE WHEN (GROUPING(Data_type) = 1) THEN 'ALL'
ELSE ISNULL(Data_type, 'UNKNOWN')
END AS Data_type,
SUM(Type_id) AS Type_idSum
FROM Staging.Data_Type
GROUP BY Data_type WITH ROLLUP
Aug 2, 2010
Min & Max percent in T-SQL
--top 20%
SELECT min(percent_outbound_calls)
FROM (SELECT TOP 20 PERCENT percent_outbound_calls
FROM scorecard_outlier
ORDER BY percent_outbound_calls desc)A
--bottom 20%
SELECT max(percent_outbound_calls)
FROM (SELECT TOP 20 PERCENT percent_outbound_calls
FROM scorecard_outlier
ORDER BY percent_outbound_calls asc)A
SELECT min(percent_outbound_calls)
FROM (SELECT TOP 20 PERCENT percent_outbound_calls
FROM scorecard_outlier
ORDER BY percent_outbound_calls desc)A
--bottom 20%
SELECT max(percent_outbound_calls)
FROM (SELECT TOP 20 PERCENT percent_outbound_calls
FROM scorecard_outlier
ORDER BY percent_outbound_calls asc)A
Subscribe to:
Posts (Atom)