troubleshooting Question

Odd group by clause error

Avatar of Zack
ZackFlag for Australia asked on
DatabasesMicrosoft SQL ServerSQL
3 Comments1 Solution101 ViewsLast Modified:
Hi EE,

The SQL Query i have written:

SELECT
'DB_NAME' = db.name,
'FILE_NAME' = mf.name,
'FILE_TYPE' = mf.type_desc,
'FILE_PATH' = mf.physical_name,
'Size in MB' = CAST(((SUM(mf.size)* 8) / 1024.0) AS DECIMAL(18,2) )
FROM
sys.databases db
INNER JOIN sys.master_files mf
ON db.database_id = mf.database_id
Where DB.state = 0 
Group by  GROUPING SETS
              (
                     (db.name, Type_Desc),
                     (mf.size)
              )

Error: Column 'sys.master_files.name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

I don't understand how this error is occurring can someone assist any help is welcome.

Thank you.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros