## Calculating percentages for multiple columns

 Author Message ishaan99 SSCertifiable Group: General Forum Members Points: 5126 Visits: 306 I have a table which has structure something likeID ColA ColB ColC 1 1 1 02 0 1 13 0 0 14 1 1 15 1 1 0Now there are 5 recordsi need to calculate percentage of each col ColA, ColB, ColC to see whats percentage of each col has value 1. ANy help in getting this sql will be greatly appreciated. I want to avoid using too many variables . any direct way of calculating this in 1 sql. TIA Jack Corbett SSC Guru Group: General Forum Members Points: 170427 Visits: 15154 This works if your data is always 1 and 0.`Declare @table table(id int, colA int, colb int, colc int)Insert into @tableSelect1 , 1 , 1 , 0Union AllSelect2, 0 , 1 , 1Union AllSelect3 , 0, 0 , 1Union AllSelect4 , 1 , 1, 1Union AllSelect5 , 1, 1 , 0Select Sum(cola)/Convert(Float, Count(id)), Sum(colb)/Convert(Float, Count(id)), Sum(Colc)/Convert(Float, Count(id))From @table`Will there ever be values other than 1 or 0? If so how do you know what value you are trying to find the percentage for? Jack Corbett Consultant Straight Path Solutions Dont let the good be the enemy of the best. -- Paul FlemingAt best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at workCheck out these links on how to get faster and more accurate answers: Forum Etiquette: How to post data/code on a forum to get the best helpNeed an Answer? Actually, No ... You Need a QuestionHow to Post Performance ProblemsCrosstabs and Pivots or How to turn rows into columns Part 1Crosstabs and Pivots or How to turn rows into columns Part 2 ishaan99 SSCertifiable Group: General Forum Members Points: 5126 Visits: 306 Cool, that worked so well. Thanks Jack