I have a Stored Procedure that does exactly what I want, but I'm wondering if there's a better way to write it. Instead of returning individual variables, I would like to just return a query recordset with the same info.
The info I'm trying to pull is actually pretty simple. In my table, I have several bit columns for Sales, Quality, Production, etc... I need to get a count of how many of each of them have a value of 1. What I have below works, I just wind up with 16 individual variables. I would like to have each of them as a value in a query instead.
Is this something that can be easily done, or should I just keep going like I have it? I'm using SQL Server 2000 if that helps.
Hope This Helps!
ECAR
ECAR Technologies
"My work is a game, a very serious game." - M.C. Escher
The info I'm trying to pull is actually pretty simple. In my table, I have several bit columns for Sales, Quality, Production, etc... I need to get a count of how many of each of them have a value of 1. What I have below works, I just wind up with 16 individual variables. I would like to have each of them as a value in a query instead.
Code:
Set @Totals = (Select Count(*) From dbo.Incidents Where Removed = 0)
Set @Sales = (Select Count(*) From dbo.Incidents Where Removed = 0 And Sales = 1)
Set @Quality = (Select Count(*) From dbo.Incidents Where Removed = 0 And Quality = 1)
Set @Production = (Select Count(*) From dbo.Incidents Where Removed = 0 And Production = 1)
Set @Complaint = (Select Count(*) From dbo.Incidents Where Removed = 0 And Complaint = 1)
Set @Observation = (Select Count(*) From dbo.Incidents Where Removed = 0 And Observation = 1)
Set @OrderEntry = (Select Count(*) From dbo.Incidents Where Removed = 0 And OrderEntry = 1)
Set @Damage = (Select Count(*) From dbo.Incidents Where Removed = 0 And Damage = 1)
Set @Injury = (Select Count(*) From dbo.Incidents Where Removed = 0 And Injury = 1)
Set @Service = (Select Count(*) From dbo.Incidents Where Removed = 0 And Service = 1)
Set @Loading = (Select Count(*) From dbo.Incidents Where Removed = 0 And Loading = 1)
Set @ProductReturn = (Select Count(*) From dbo.Incidents Where Removed = 0 And ProductReturn = 1)
Set @Hauling = (Select Count(*) From dbo.Incidents Where Removed = 0 And Hauling = 1)
Set @Credit = (Select Count(*) From dbo.Incidents Where Removed = 0 And Credit = 1)
Set @UndeliveredLoad = (Select Count(*) From dbo.Incidents Where Removed = 0 And UndeliveredLoad = 1)
Set @WaitTime = (Select Count(*) From dbo.Incidents Where Removed = 0 And WaitTime = 1)
Hope This Helps!
ECAR
ECAR Technologies
"My work is a game, a very serious game." - M.C. Escher