-- just in case you happen to be working in a different schema
DECLARE @SchemaName NVARCHAR(MAX);

DECLARE @TableName NVARCHAR(MAX);
DECLARE @ColumnName NVARCHAR(MAX);
DECLARE @SQL NVARCHAR(MAX);

-- set it to standard here for a more reusable script
SET @SchemaName = 'dbo';

-- override it for this specific Adventure Works example
SET @SchemaName = 'SalesLT';

-- set the table and column name that you're interested in here
SET @TableName = 'Product';
SET @ColumnName = 'ProductCategoryID';

SET @SQL = N'
	SELECT TOP 100 [' + @ColumnName + N'],
		COUNT(*) AS ValueRows, 
		SUM(COUNT(*)) OVER () AS TotalRows, 
		CAST(COUNT(*) AS DECIMAL(18,2)) / SUM(COUNT(*)) OVER () AS Percentage
	FROM [' + @SchemaName + N'].[' + @TableName + N']
	GROUP BY [' + @ColumnName + N']
	ORDER BY COUNT(*) DESC;';

EXEC sp_executesql @SQL;
