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 |
|
joelhulen
Starting Member
5 Posts |
Posted - 2001-04-17 : 10:19:53
|
Hello, all.I am trying to create a stored procedure that will tell me how many columns return a bit value of 1 instead of a 0.I am going out of my mind to figure it out! I have added this code:-------------- Begin code --------------Create Stored Procedure usp_sp1@ActivityID intASSelect Sum (CAST (Heating_Supply AS int))AS Heat, Sum (CAST (Natural_Gas AS int))AS Natural_Gas, Sum (CAST (Electric AS int))AS Electric, Sum (CAST (Potable_Water AS int))AS Pot_Water, Sum (CAST (Non_Potable_Water AS int))AS Non_Pot_Water, Sum (CAST (Sewage AS int))AS Sewage, Sum (CAST (Chiller_Plant AS int))AS Chill_Plant, Sum (CAST (Pneum_Power AS int))AS Pneumonia, Sum (CAST (Misc_Utilities AS int))AS Misc_Utilities, Sum (CAST (Other_Fuel AS int))AS Other_FuelFrom tblActivityWHERE ActivityID = @ActivityID------------- End Code ------------I have (unnessesarily) summed the columns, but I did convert them from bit to int so I can perform aggregate functions.The resultset returns either a 1 or a 0 under each column. I need to count how many 1's are returned. BTW, this query returns only one row.Please help!Thanks  |
|
|
|
|
|