﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / Interesting query / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sun, 19 May 2013 20:48:55 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Interesting query</title><link>http://www.sqlservercentral.com/Forums/Topic1404129-391-1.aspx</link><description>Thanks So much Chris and it works. I recognize the deep thought you might have put in it. Thanks for your time...</description><pubDate>Tue, 08 Jan 2013 07:03:32 GMT</pubDate><dc:creator>S_Kumar_S</dc:creator></item><item><title>RE: Interesting query</title><link>http://www.sqlservercentral.com/Forums/Topic1404129-391-1.aspx</link><description>[code="sql"];WITH CTE AS(	SELECT forumId,ParentId,HitNumber,		Seq = CAST(','+CAST(forumId AS VARCHAR(2)) AS VARCHAR(20))	FROM #tab1 	WHERE ParentId IS NULL 	UNION ALL	SELECT DD2.forumId, DD2.ParentId, DD2.HitNumber,		Seq = CAST(CTE.Seq + ',' + CAST(DD2.forumId AS VARCHAR(2)) AS VARCHAR(20))	FROM #tab1 AS DD2	INNER JOIN CTE 		ON CTE.ForumId = DD2.parentId)SELECT c.forumId, c.ParentId, 	x.TotalHitNumber  FROM CTE cCROSS APPLY ( 	SELECT TotalHitNumber = SUM(HitNumber) 	FROM CTE 	WHERE Seq+',' LIKE '%,'+CAST(c.forumId AS VARCHAR(2))+',%') xORDER BY c.forumId [/code]</description><pubDate>Tue, 08 Jan 2013 06:41:42 GMT</pubDate><dc:creator>ChrisM@Work</dc:creator></item><item><title>RE: Interesting query</title><link>http://www.sqlservercentral.com/Forums/Topic1404129-391-1.aspx</link><description>Correct Sir...</description><pubDate>Tue, 08 Jan 2013 05:14:11 GMT</pubDate><dc:creator>S_Kumar_S</dc:creator></item><item><title>RE: Interesting query</title><link>http://www.sqlservercentral.com/Forums/Topic1404129-391-1.aspx</link><description>So for each forum ID, you want the number of hits, including the number of hits for any child forums.4	885	5716	14639	203811	12815	5410	10658	4993	118413	789</description><pubDate>Tue, 08 Jan 2013 05:08:44 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>RE: Interesting query</title><link>http://www.sqlservercentral.com/Forums/Topic1404129-391-1.aspx</link><description>Problem is :I have hard coded the query for ForumId=9. But I need the SUM of hits for All ForumIds individually. Something like:ForumId   SumOfHitCount9             20383              1184.................................................</description><pubDate>Tue, 08 Jan 2013 04:36:13 GMT</pubDate><dc:creator>S_Kumar_S</dc:creator></item><item><title>RE: Interesting query</title><link>http://www.sqlservercentral.com/Forums/Topic1404129-391-1.aspx</link><description>[quote][b]S_Kumar_S (1/8/2013)[/b][hr]Sorry for confusion. I am trying to remove a user defined function already built, not the sum function[/quote]Ok what is the problem you are having with the code, it seems to work for me.</description><pubDate>Tue, 08 Jan 2013 04:26:28 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>RE: Interesting query</title><link>http://www.sqlservercentral.com/Forums/Topic1404129-391-1.aspx</link><description>Sorry for confusion. I am trying to remove a user defined function already built, not the sum function</description><pubDate>Tue, 08 Jan 2013 04:25:26 GMT</pubDate><dc:creator>S_Kumar_S</dc:creator></item><item><title>RE: Interesting query</title><link>http://www.sqlservercentral.com/Forums/Topic1404129-391-1.aspx</link><description>What function are you trying to remove?The SUM?[strike]I would of thought that Azure would come with the bulit in aggregating functions as standard.[/strike][url]http://msdn.microsoft.com/en-us/library/windowsazure/ee336248.aspx#aggregate[/url]Azure does use the standard aggregating functions</description><pubDate>Tue, 08 Jan 2013 04:23:43 GMT</pubDate><dc:creator>anthony.green</dc:creator></item><item><title>Interesting query</title><link>http://www.sqlservercentral.com/Forums/Topic1404129-391-1.aspx</link><description>Hi AllFirst schema:create table tab1 (forumId int Primary key,ParentId int,HitNumber int)insert into tab1select 3,	9,	119 UNION ALLselect 4,	NULL,	88  UNION ALLselect 5,	NULL,	72  UNION ALLselect 6	,NULL	,1463 UNION ALLselect 8	,5	,499 UNION ALLselect 9	,NULL	,65 UNION ALLselect 10,	3,	1065  UNION ALLselect 11,	NULL,	128 UNION ALLselect 13,	9	,789 UNION ALLselect 15	,NULL,	54;WITH CTE AS(        SELECT forumId,ParentId,HitNumber        FROM [tab1] 		WHERE ForumID=9        UNION ALL        SELECT DD2.forumId,DD2.ParentId,DD2.HitNumber        FROM tab1 as DD2        INNER JOIN CTE ON DD2.parentId=CTE.ForumId)SELECT SUM(HitNumber) FROM CTE --select * from CTEIn Above table , ForumId 9 is Parent to ForumId 3 and 13. 3 Is parent to 10. Now as you can see, I have hard coded the query for ForumId=9. But I need the SUM of hits for All ForumIds. So I need SUM of Hits for ForumID 9,3,13,10.I don't have to use a funtion. In fact the whole exercise is for removing function for Azure.Help pls.</description><pubDate>Tue, 08 Jan 2013 04:15:59 GMT</pubDate><dc:creator>S_Kumar_S</dc:creator></item></channel></rss>