﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>InstantASP Community Forums / Old Forums / InstantKB.NET 1.x  / Query Article Count of all subarticles / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>InstantASP Community Forums</description><link>http://community.instantasp.co.uk/</link><webMaster>sales@instantasp.co.uk</webMaster><lastBuildDate>Fri, 09 Jan 2009 10:51:41 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Query Article Count of all subarticles</title><link>http://community.instantasp.co.uk/Topic6996-26-1.aspx</link><description>Well this took some figuring out and since I eventually got what I wanted I thought I would share.&lt;P&gt;This next SQL code gives a total count of articles which appear in both the nodes listed in the SQL.  Great for counting duplicates. :D&lt;/P&gt;&lt;P&gt;[code]SELECT count(distinct questionid) AS count FROM instantkb_articlestreenodes &lt;/P&gt;&lt;P&gt;WHERE questionid IN &lt;/P&gt;&lt;P&gt;( &lt;/P&gt;&lt;P&gt;SELECT questionid FROM instantkb_articlestreenodes &lt;/P&gt;&lt;P&gt;WHERE nodeID IN ('2Q3U7V', '8W6V7H') &lt;/P&gt;&lt;P&gt;GROUP BY questionID &lt;/P&gt;&lt;P&gt;HAVING COUNT(*)   &amp;gt; 1 &lt;P&gt;)[/code]</description><pubDate>Thu, 29 Nov 2007 14:52:44 GMT</pubDate><dc:creator>RobH</dc:creator></item><item><title>RE: Query Article Count of all subarticles</title><link>http://community.instantasp.co.uk/Topic6996-26-1.aspx</link><description>Yes I know this is a 2 year old thread but it's as close as can be to what I need without actually giving me exactly what I need.&lt;/P&gt;&lt;P&gt;Let me explain (this isn't going to be easy)....&lt;/P&gt;&lt;P&gt;My SQL is at best err basic to n00b status so if you reply please be as plain as possible.&lt;/P&gt;&lt;P&gt;I have been tasked with coming up with a KB status page (web page) with various amounts of figures on it that the senior managers can look over and see what's what.&lt;/P&gt;&lt;P&gt;I've done most of what they want but the last one is killing me.&lt;/P&gt;&lt;P&gt;I want a category count per individual category as per this post BUT this is where it gets tricky.  We have over 500 categories most END of the tree categories are named the same so we have &lt;/P&gt;&lt;P&gt;Product1 - with sub categories of faq, trouble shooting, training, user guides etc etc&lt;/P&gt;&lt;P&gt;product2 - with sub categories of faq, trouble shooting, training, user guides etc etc&lt;/P&gt;&lt;P&gt;select t.parentnodeid, t.nodename, count(*) 'Count' from instantkb_articlestreenodes AS a&lt;BR&gt;join instantkb_tree as t&lt;BR&gt;ON a.nodeid=t.nodeid&lt;BR&gt;group by t.parentnodeid, a.nodeid, t.nodename&lt;BR&gt;order by t.nodename&lt;/P&gt;&lt;P&gt;The above code gives me what I want but I kind figure out how to get the &lt;STRONG&gt;actual&lt;/STRONG&gt; parentnodeid to show the actual nodename, in my example I have 0F6O0A - FAQ - 51 (parentnodeid - original nodeid - count).  So in this example if it showed (parentnodeid as nodename - end nodename - count) that would be ace :)&lt;/P&gt;&lt;P&gt;And to top it all off I am hoping to make it so that when a new category gets added (yes there willl be more) I don't have to go back to the web page stats and alter the code.&lt;/P&gt;&lt;P&gt;Any kind sole help me recover some hair I pulled out ?? :)</description><pubDate>Tue, 13 Nov 2007 10:37:34 GMT</pubDate><dc:creator>RobH</dc:creator></item><item><title>RE: Query Article Count of all subarticles</title><link>http://community.instantasp.co.uk/Topic6996-26-1.aspx</link><description>Many thanks for your kind words Bill, your knowledge base is looking great :)&lt;/P&gt;&lt;P&gt;Please don't hesitate to contact us again if you have any further questions,</description><pubDate>Thu, 02 Jun 2005 06:30:29 GMT</pubDate><dc:creator>Ryan Healey</dc:creator></item><item><title>RE: Query Article Count of all subarticles</title><link>http://community.instantasp.co.uk/Topic6996-26-1.aspx</link><description>Perfect!  Our KB is now live (with modifications).  Feel free to check it out at &lt;a target="_blank" href="http://www.atalasoft.com/kb"&gt;www.atalasoft.com/kb&lt;/A&gt;.  A big improvement over the previous software we used.  Thanks for your help and keep up the good work.</description><pubDate>Wed, 01 Jun 2005 20:57:39 GMT</pubDate><dc:creator>flyguy</dc:creator></item><item><title>RE: Query Article Count of all subarticles</title><link>http://community.instantasp.co.uk/Topic6996-26-1.aspx</link><description>[quote][b]flyguy (6/1/2005)[/b][hr]Thanks!  But how would that query be modified to count articles within a specific category (and all sub categories)?  That query seems to count all articles in the entire database.[/quote]&lt;/P&gt;&lt;P&gt;Dear flyguy,&lt;/P&gt;&lt;P&gt;Sorry, I misunderstood. Please check below to see if this procedure can solve your problem:&lt;BR&gt;&lt;/P&gt;&lt;P&gt;Create Procedure CountArticleInCategory(@strNodeID nvarchar(75)) &lt;BR&gt;AS&lt;/P&gt;&lt;P&gt;SELECT Count(DISTINCT (InstantKB_Articles.QuestionID)) AS QtyArticleInCategory FROM InstantKB_Articles INNER JOIN&lt;BR&gt;InstantKB_ArticlesTreeNodes ON InstantKB_Articles.QuestionID = InstantKB_ArticlesTreeNodes.QuestionID INNER JOIN&lt;BR&gt;InstantKB_TreeRoles ON InstantKB_ArticlesTreeNodes.NodeID = InstantKB_TreeRoles.NodeID INNER JOIN&lt;BR&gt;InstantKB_Roles ON InstantKB_TreeRoles.RoleID = InstantKB_Roles.RoleID&lt;BR&gt;WHERE InstantKB_TreeRoles.NodeID IN ( SELECT distinct(t4.NodeID)  FROM InstantKB_Tree t1&lt;BR&gt;INNER JOIN InstantKB_Tree t2 ON t1.Nodeid = t2.ParentNodeID or t2.Nodeid =  @strNodeID &lt;BR&gt;INNER JOIN InstantKB_Tree t3 ON t2.Nodeid = t3.ParentNodeID or t3.Nodeid =  @strNodeID &lt;BR&gt;INNER JOIN InstantKB_Tree t4 ON t3.Nodeid = t4.ParentNodeID or t4.Nodeid =  @strNodeID &lt;BR&gt;where t1.parentnodeid =   @strNodeID   or t1.Nodeid =   @strNodeID )&lt;BR&gt;&lt;/P&gt;&lt;P&gt;return&lt;/P&gt;&lt;P&gt;GO</description><pubDate>Wed, 01 Jun 2005 14:58:28 GMT</pubDate><dc:creator>Carlos Muniz</dc:creator></item><item><title>RE: Query Article Count of all subarticles</title><link>http://community.instantasp.co.uk/Topic6996-26-1.aspx</link><description>Thanks!  But how would that query be modified to count articles within a specific category (and all sub categories)?  That query seems to count all articles in the entire database.</description><pubDate>Wed, 01 Jun 2005 08:27:06 GMT</pubDate><dc:creator>flyguy</dc:creator></item><item><title>RE: Query Article Count of all subarticles</title><link>http://community.instantasp.co.uk/Topic6996-26-1.aspx</link><description>To Count all articles:&lt;/P&gt;&lt;P&gt;select count(DISTINCT(InstantKB_Articles.QuestionID))As QuantityofArticles FROM InstantKB_Articles INNER JOIN&lt;BR&gt;InstantKB_ArticlesTreeNodes ON InstantKB_Articles.QuestionID = InstantKB_ArticlesTreeNodes.QuestionID INNER JOIN&lt;BR&gt;InstantKB_TreeRoles ON InstantKB_ArticlesTreeNodes.NodeID = InstantKB_TreeRoles.NodeID INNER JOIN&lt;BR&gt;InstantKB_Roles ON InstantKB_TreeRoles.RoleID = InstantKB_Roles.RoleID&lt;BR&gt;&lt;/P&gt;&lt;P&gt;To Count only public articles:&lt;/P&gt;&lt;P&gt;select count(DISTINCT(InstantKB_Articles.QuestionID))As QuantityofArticles FROM InstantKB_Articles INNER JOIN&lt;BR&gt;InstantKB_ArticlesTreeNodes ON InstantKB_Articles.QuestionID = InstantKB_ArticlesTreeNodes.QuestionID INNER JOIN&lt;BR&gt;InstantKB_TreeRoles ON InstantKB_ArticlesTreeNodes.NodeID = InstantKB_TreeRoles.NodeID INNER JOIN&lt;BR&gt;InstantKB_Roles ON InstantKB_TreeRoles.RoleID = InstantKB_Roles.RoleID&lt;BR&gt;where InstantKB_TreeRoles.RoleID = 1&lt;/P&gt;&lt;P&gt; You can change the where condition as you please. eg.: if you would like to see only public and customers articles you need to check via select * from InstantKB_Roles where the RoleID is the customer role id and then add OR statements like below:&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;where InstantKB_TreeRoles.RoleID = 1 or InstantKB_TreeRoles.RoleID = 3</description><pubDate>Wed, 01 Jun 2005 08:22:44 GMT</pubDate><dc:creator>Carlos Muniz</dc:creator></item><item><title>Query Article Count of all subarticles</title><link>http://community.instantasp.co.uk/Topic6996-26-1.aspx</link><description>We have been customizing InstantKB to fit our needs, and the one area where we could use a little help is writing a query that will return the article count of a category and all subcategories.  Currently we have written a recursive routine which loops through all articles of the parent and child categories for a count.  However for articles that appear in multiple categories are counted twice.  I'm not sure the current database structure is really setup for this type of heirarchy, but is there a SQL Query you can supply us to count all articles including those in subcategories?&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR&gt;-Bill</description><pubDate>Tue, 31 May 2005 13:51:53 GMT</pubDate><dc:creator>flyguy</dc:creator></item></channel></rss>