I'm trying to write a stored procedure that can gather some database statistics. I'm running SQL Server 2000 and am trying to take advantage of @@rowcount, which I've read is better on performance than COUNT(). Below, you'll see I've used several SELECT statements to fill three variables with the @@rowcount function. My problem is that I only want to return one recordset ... the one containing "TodaysOrders," "UnprocessedOrders," "TotalOrders" so I can access them in an ASP page. Is it possible to drop the prior SELECT statements or somehow create output variables?
Code:CREATE PROCEDURE dbo.sp_CountRecords AS DECLARE @today INT, @unprocessed INT, @total INT SELECT * FROM orders WHERE TransTime > CONVERT(DATETIME, LEFT(CONVERT(VARCHAR, GETDATE(), 120), 10)) SET @today = @@rowcount SELECT * FROM orders WHERE TransactionID in (SELECT TransactionID FROM orderstatus WHERE Status = 0) SET @unprocessed = @@rowcount SELECT * FROM orders SET @total = @@rowcount SELECT @today AS TodaysOrders, @unprocessed AS UnprocessedOrders, @total AS TotalOrders






Bookmarks