Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Samira writes "I need to find out a percentage value in a select SUM(CASE WHEN.... THEN WHEN.... THEN WHEN..... THEN ELSE 0 END) AS Percentagehow do i include the percentage calculation inside the query above?Windows 2003 serverSQL 2000 server + sp 3"
jsmith8858
Dr. Cross Join
7423 Posts
Posted - 2004-12-06 : 09:20:37
Percentage of WHAT ? In general, divide the each number by the total of all numbers to get the percentage, but I'm sure you already know that.We need some more info to help you. sample data would help as well. in the meantime, consider this:
select a.ID, a.value, (1.0 * a.value / b.total) as PCTfrom data ainner join (select ID, sum(value) as Total from data group by id) bon a.ID = b.id