I have the following query, which is trying to figure out the percentage of a certain product compared to the total number of products. IE: [Product Count] / [Total Products
Shouldn't that be:
;WITH totalCount AS(
SELECT
CAST(COUNT(id) as Integer)as totalCount
FROM TABLE_NAME
)
SELECT
((CAST(COUNT(DISTINCT id) as Integer)*100/(SELECT count(*) FROM totalCount))) as 'Percent'
FROM TABLE_NAME
Note the SELECT COUNT(*). Also, you should multiply before you divide, otherwise you'll always get zero