I'm working in MSSQL 2008 on a stored procedure for data profiling. I have a script that returns the distinct values and count of each using the following dynamic SQL:
SELECT @SQL = N'SELECT ' + @FieldName + ', COUNT(*) AS [Frequency] FROM ' + @TableName + ' GROUP BY ' + @FieldName + ' ORDER BY [Frequency] DESC';
I would like to add percentage of each distinct count to that output. I think the technique used here would work for what I'm doing but I can't figure out how to integrate the two. The desired output would show the distinct values, the count of each, and the percentage of each.
Thanks in advance for any help.