Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 24th, 2007, 05:41 AM
Registered User
 
Join Date: Jan 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default getting summary in a stored procedure

Hi, I am busy with a stored procedure for a group press database.

I have 2 tables: tbl_groups and tbl_articles

tbl_groups (intID, strGroupName)
tbl_articles (intID, intGroupID, txtArticle)

It is no problem to get the groups with articles but I also need the summary of articles for each group seperate.

This is what I have now:

Code:
ALTER PROCEDURE lbl_brands_lst    
(
@intGroupTypeID int = 0
)

AS
    SET NOCOUNT ON 

    SELECT        

                1                AS tag,
            null                AS parent,    
            g.intID                AS [Brand!1!ID!element],    
            g.strGroupName        AS [Brand!1!Name!element],
            g.intGroupTypeID    AS [Brand!1!GrouptypeID!element],
    (SELECT count(a.intID) FROM tbl_Articles a 
    INNER JOIN tbls_Groups g ON a.intGroupID = g.intID) AS [Brand!1!Summary!element]


            FROM         tbls_Groups g
            INNER JOIN tbl_Articles a ON a.intGroupID = g.intID

            WHERE g.intGroupTypeID = @intGroupTypeID            

            ORDER BY g.strGroupName ASC
            FOR XML EXPLICIT

But the summary node gives the total result of all articles and not per group. How is it possible to filter this in the "SELECT COUNT.." part of the stored procedur.

Thanks already!

Smiter




 
Old April 24th, 2007, 05:37 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Its just a wild shot but maybe by using GROUP BY in the outer query.






Similar Threads
Thread Thread Starter Forum Replies Last Post
stored procedure prashant_telkar SQL Server 2000 1 July 9th, 2007 07:57 AM
This Stored Procedure rao965 SQL Server 2000 2 July 2nd, 2007 07:21 PM
Stored Procedure jezywrap SQL Server ASP 1 January 3rd, 2007 12:29 AM
Help On Stored Procedure desireemm SQL Language 2 October 31st, 2005 07:11 PM
Stored Procedure help flyin SQL Server 2000 6 July 25th, 2004 05:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.