I'm trying to write a metadata query (sys.tables and sys.columns) that also contains an additional column with an aggregate on that column's data. The output I'm looking for will be a table with these columns:
- SchemaName
- TableName
- ColumnName
- MaxValueForColumn (or similar)
I know how to get the first three columns by querying metadata, and I know how to write a regular query, but I'm having trouble wrapping my head around how to combine the two tasks into a single output. I think I may need to write a function, but I'm still confused about how to join the sys tables to the regular table.