Connecting Tech Pros Worldwide Forums | Help | Site Map

I have a Problem With Stored proc_ help needed

Member
 
Join Date: Oct 2007
Posts: 36
#1: Apr 22 '08
Hi,.. to all..

I have quierry in stored procecedure. ie:

select distinct Member_ID,m_displayname,brand_name,Brand_ID,produc t_id,
count(product_id) as ImagesCount from dbo.vSMgr_ImageReport
where brand_owner = @MemberID
group by brand_id, brand_name,product_id,Member_ID,m_displayname.

In the above quierry ImagesCount is the sum(product_id)...

Now i need sum(ImagesCount) how can i get using that same quierry...

Help shold be thankfull...

@shraf

Member
 
Join Date: Dec 2007
Posts: 81
#2: Apr 23 '08

re: I have a Problem With Stored proc_ help needed


Try it like this:
Expand|Select|Wrap|Line Numbers
  1. select *, sum(ImagesCount) As SumImagesCount
  2. from
  3. (
  4. select distinct Member_ID,m_displayname,brand_name,Brand_ID,product_id,
  5. count(product_id) as ImagesCount from dbo.vSMgr_ImageReport          
  6. where brand_owner = @MemberID
  7. group by brand_id, brand_name,product_id,Member_ID,m_displayname
  8. )
  9.  
If your purpose of getting the sum of all ImagesCount is just for display, you might consider doing it in your front-end application rather than doing it in your query where it causes additional overhead.
Reply