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.
| Author |
Topic |
|
evanburen
Posting Yak Master
167 Posts |
Posted - 2007-04-25 : 16:21:21
|
| SELECT Industry, 100.0 * SUM(CASE when ceoischairman = 'yes' then 1 else 0 end) / COUNT(DISTINCT CompID) AS [YesPercent], 100.0 * SUM(CASE when ceoischairman = 'no' then 1 else 0 end) / COUNT(DISTINCT CompID) AS [NoPercent] FROM TCompaniesGROUP BY IndustryORDER BY IndustryThis code above is working as I need it but I need to insert some additional functionality. ThanksI need to add something like this:IF YesPercent > NoPercent UPDATE tableX SET CEOIsChairman='Yes' WHERE Industry='<the industry value being evaluated>'Else If NoPercent > YesPercent UPDATE tableX SET CEOIsChairman='No' WHERE Industry='<the industry value being evaluated>'Else UPDATE tableX SET CEOIsChairman='Equal' WHERE Industry='<the industry value being evaluated>'End |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-04-25 : 16:38:30
|
Perhaps something along these lines:update tableX set CEOIsChairman = CASE WHEN YesPercent > NoPercent THEN 'Yes' WHEN NoPercent > YesPercent THEN 'No' ELSE 'Equal' END You can replace the YesPercent and NoPercent with the computation you already have.. Try running the statement as a SELECT instead of an UPDATE to make sure the right values are being updated and with what you intend to too.************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
|
|
|