Hi everyone,
I've a calculate query as below but actually the result couldn't show the decimal numbers, it shows rounded with decimal zeros
does I did anything wrong? I've tried with STR, CAST & Convert with no luck
SELECT
P,
T,
CD,
count([ID]) AS [Total],
SUM(COUNT(*)) OVER (PARTITION BY [P], [T]) AS TTotal,
convert(varchar(50),count([ID])*100/SUM(COUNT(*)) OVER (PARTITION BY [P], [T])) + '%' AS Percentage
FROM
tbl
GROUP BY
[P],
[T],
[CD]
result example
On this line
count([ID])*100
Do this
count([ID])*100.0
Does that give you the decimal output?
September 20, 2023 at 2:03 pm
yes, it works.
appreciate your reply.
September 21, 2023 at 9:54 pm
yes, it works.
appreciate your reply.
The question now is, do you understand why the fix worked and why you were getting the original issue?
The other question is, do you know what the problem is and how to fix it when you get the possible "Divide by 0" error?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply