[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

How i return the sum of a range numeric column count values isql 2005 server

Expert: I need to return the Sum of cnt (totals of all counts) in the SP procedure below with along with the other data back to my dot net app. Could someone kindly show me what changes I have to make to my SP  to return the Sum ?  thanks for your help here.  

ALTER procedure [dbo].[GetRatingCount]
   @startdate datetime,
   @enddate datetime
as
ALTER procedure [dbo].[GetRatingCount]
   @startdate datetime,
   @enddate datetime
as
set nocount on
select rating_type, count(*) cnt
from TableA
where Date1 >= @startdate
and  Date1 < @enddate
group by rating_type
0
tcmmaxt
Asked:
tcmmaxt
  • 2
1 Solution
 
bprojoeCommented:
you can return a second table from your Sp.  Just add another select.
select count(*) as cnt
from TableA
where Date1 >= @startdate
and  Date1 < @enddate

Or you can do a union and add one more row to your table
select rating_type, count(*) cnt
from TableA
where Date1 >= @startdate
and  Date1 < @enddate
group by rating_type
Union
select count(*) as cnt
from TableA
where Date1 >= @startdate
and  Date1 < @enddate
0
 
bprojoeCommented:
correction, after union the query should be something like.  So you will know that the row called Total Count is what you want.
select 'Total Count', count(*) as cnt
from TableA
where Date1 >= @startdate
and  Date1 < @enddate
0
 
tcmmaxtAuthor Commented:
nice
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now