views:

152

answers:

2

Table UserData (UserID, Sales, Credits)

I need to return the SUM of sales, sum of credits and the # of rows returned for a given date range.

Is it possible in 1 query?

+6  A: 
SELECT COUNT(*), SUM(Sales), SUM(Credits)
FROM UserData
WHERE TransactionDate BETWEEN @StartDate AND @EndDate
Mehrdad Afshari
A: 

You can also give names to the computed columns like this


   SELECT 
      COUNT(*) AS NumRows, SUM(Sales) AS SalesTotal, SUM(Credits) AS CreditsTotal
   FROM UserData
   WHERE TransactionDate BETWEEN @StartDate AND @EndDate
sventech