<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; Fix: Error 130: Cannot perform an aggregate function on an expression containing an aggregate or a subquery</title>
	<atom:link href="http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sun, 21 Mar 2010 03:48:32 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Steve G</title>
		<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-60666</link>
		<dc:creator>Steve G</dc:creator>
		<pubDate>Thu, 04 Feb 2010 14:53:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-60666</guid>
		<description>Dave,

Regarding your solution, suppose I have to take average of the count of rows, grouped by hour.

So I have the following data:

row 1: 02/01/10 05:00:00
row 2: 02/01/10 07:10:00
row 3  02/01/10 12:00:00
row 4: 02/02/10 05:00:00
row 5: 02/02/10 05:23:00
row 6: 02/02/10 05:50:00
row 7: 02/02/10 07:32:00

and I want the results to be average of the row count, hour:
avg_row_count    hr
===========    ==
2                          05
1                          07
0.5                       12

I cannot write the sql because of the aggragation being done on hour.</description>
		<content:encoded><![CDATA[<p>Dave,</p>
<p>Regarding your solution, suppose I have to take average of the count of rows, grouped by hour.</p>
<p>So I have the following data:</p>
<p>row 1: 02/01/10 05:00:00<br />
row 2: 02/01/10 07:10:00<br />
row 3  02/01/10 12:00:00<br />
row 4: 02/02/10 05:00:00<br />
row 5: 02/02/10 05:23:00<br />
row 6: 02/02/10 05:50:00<br />
row 7: 02/02/10 07:32:00</p>
<p>and I want the results to be average of the row count, hour:<br />
avg_row_count    hr<br />
===========    ==<br />
2                          05<br />
1                          07<br />
0.5                       12</p>
<p>I cannot write the sql because of the aggragation being done on hour.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dev</title>
		<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-60013</link>
		<dc:creator>dev</dc:creator>
		<pubDate>Thu, 21 Jan 2010 05:12:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-60013</guid>
		<description>great Blog Pinal keep it up...
Ur suggessions are dam helpful
 thnx...

-DEV</description>
		<content:encoded><![CDATA[<p>great Blog Pinal keep it up&#8230;<br />
Ur suggessions are dam helpful<br />
 thnx&#8230;</p>
<p>-DEV</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Silre</title>
		<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-54590</link>
		<dc:creator>Silre</dc:creator>
		<pubDate>Fri, 07 Aug 2009 15:24:24 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-54590</guid>
		<description>Thanks, that  worked appropriately for me.</description>
		<content:encoded><![CDATA[<p>Thanks, that  worked appropriately for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: phani</title>
		<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-43895</link>
		<dc:creator>phani</dc:creator>
		<pubDate>Fri, 24 Oct 2008 14:24:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-43895</guid>
		<description>hi dave, 

i need to use Max() like this,

select id, Max( (select y from z where t =&#039;a&#039;)) from c 
group by e,f
when I use the subquery, I was getting same above error...

please help.</description>
		<content:encoded><![CDATA[<p>hi dave, </p>
<p>i need to use Max() like this,</p>
<p>select id, Max( (select y from z where t =&#8217;a')) from c<br />
group by e,f<br />
when I use the subquery, I was getting same above error&#8230;</p>
<p>please help.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hannahgrace</title>
		<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-43563</link>
		<dc:creator>hannahgrace</dc:creator>
		<pubDate>Tue, 07 Oct 2008 08:42:28 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-43563</guid>
		<description>i have a code similar to the code you gave, i just changed the fields.. 


SELECT SUM(t.Total Applications)
    FROM
    (
   SELECT    dbo.aBarangay.BarangayName, (COUNT(BPAS.Permits.PermitID)) AS &#039;Total Applications&#039;
FROM         BPAS.Permits LEFT OUTER JOIN
                      BPAS.BuildingRecord ON BPAS.Permits.BldgID = BPAS.BuildingRecord.BldgID AND 
                      BPAS.Permits.BldgID = BPAS.BuildingRecord.BldgID RIGHT OUTER JOIN
                      dbo.aBarangay ON BPAS.BuildingRecord.BrgyID = dbo.aBarangay.BarangayId
GROUP BY dbo.aBarangay.BarangayName
ORDER BY dbo.aBarangay.BarangayName
    ) T

it gives me this error:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near &#039;Applications&#039;.
Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword &#039;ORDER&#039;.

what should i do?

thanks!</description>
		<content:encoded><![CDATA[<p>i have a code similar to the code you gave, i just changed the fields.. </p>
<p>SELECT SUM(t.Total Applications)<br />
    FROM<br />
    (<br />
   SELECT    dbo.aBarangay.BarangayName, (COUNT(BPAS.Permits.PermitID)) AS &#8216;Total Applications&#8217;<br />
FROM         BPAS.Permits LEFT OUTER JOIN<br />
                      BPAS.BuildingRecord ON BPAS.Permits.BldgID = BPAS.BuildingRecord.BldgID AND<br />
                      BPAS.Permits.BldgID = BPAS.BuildingRecord.BldgID RIGHT OUTER JOIN<br />
                      dbo.aBarangay ON BPAS.BuildingRecord.BrgyID = dbo.aBarangay.BarangayId<br />
GROUP BY dbo.aBarangay.BarangayName<br />
ORDER BY dbo.aBarangay.BarangayName<br />
    ) T</p>
<p>it gives me this error:</p>
<p>Msg 102, Level 15, State 1, Line 1<br />
Incorrect syntax near &#8216;Applications&#8217;.<br />
Msg 156, Level 15, State 1, Line 10<br />
Incorrect syntax near the keyword &#8216;ORDER&#8217;.</p>
<p>what should i do?</p>
<p>thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mahathi</title>
		<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-42677</link>
		<dc:creator>Mahathi</dc:creator>
		<pubDate>Thu, 11 Sep 2008 04:42:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-42677</guid>
		<description>The query I used for it is

ALTER procedure [dbo].[mostFrequentAllocations](@ClientId bigint)
as
begin
select a.AllocName, max(av.AllocationId) as Cnt from (select count(AllocId) as AllocationId from AllocationVisit)av, Allocations a,Clients C where A.ClientId=C.ClientId and c.ClientId=@ClientId 
group by a.AllocName

end</description>
		<content:encoded><![CDATA[<p>The query I used for it is</p>
<p>ALTER procedure [dbo].[mostFrequentAllocations](@ClientId bigint)<br />
as<br />
begin<br />
select a.AllocName, max(av.AllocationId) as Cnt from (select count(AllocId) as AllocationId from AllocationVisit)av, Allocations a,Clients C where A.ClientId=C.ClientId and c.ClientId=@ClientId<br />
group by a.AllocName</p>
<p>end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mahathi</title>
		<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-42676</link>
		<dc:creator>Mahathi</dc:creator>
		<pubDate>Thu, 11 Sep 2008 04:39:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-42676</guid>
		<description>Hi,
  First time when I used this, it worked correctly. But now what happens is that, if the total count of all the records is 16 and if there are four items on which we apply count, it is dividing those 16 records between the four items and displaying the result.

Please help me in that error.

Regards
Mahathi</description>
		<content:encoded><![CDATA[<p>Hi,<br />
  First time when I used this, it worked correctly. But now what happens is that, if the total count of all the records is 16 and if there are four items on which we apply count, it is dividing those 16 records between the four items and displaying the result.</p>
<p>Please help me in that error.</p>
<p>Regards<br />
Mahathi</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mahathi</title>
		<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-42583</link>
		<dc:creator>Mahathi</dc:creator>
		<pubDate>Tue, 09 Sep 2008 07:15:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-42583</guid>
		<description>Hi Pinal Dave,
   Thank you for the query. It worked appropriately for me.

Regards
Mahathi.</description>
		<content:encoded><![CDATA[<p>Hi Pinal Dave,<br />
   Thank you for the query. It worked appropriately for me.</p>
<p>Regards<br />
Mahathi.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kin</title>
		<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-33372</link>
		<dc:creator>kin</dc:creator>
		<pubDate>Wed, 30 Jan 2008 17:13:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-33372</guid>
		<description>I don&#039;t understand how you can reference t.royaltycounts in your solution. Is that what the capital T is for outside the parenthesis?</description>
		<content:encoded><![CDATA[<p>I don&#8217;t understand how you can reference t.royaltycounts in your solution. Is that what the capital T is for outside the parenthesis?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-11493</link>
		<dc:creator>pinaldave</dc:creator>
		<pubDate>Thu, 06 Sep 2007 22:03:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-11493</guid>
		<description>Chintan,
I do not see relation to your comment with post so I will delete it soon.
Regards,
Pinal</description>
		<content:encoded><![CDATA[<p>Chintan,<br />
I do not see relation to your comment with post so I will delete it soon.<br />
Regards,<br />
Pinal</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chintan</title>
		<link>http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-11486</link>
		<dc:creator>Chintan</dc:creator>
		<pubDate>Thu, 06 Sep 2007 21:53:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/05/16/sql-server-fix-error-130-cannot-perform-an-aggregate-function-on-an-expression-containing-an-aggregate-or-a-subquery/#comment-11486</guid>
		<description>Invalid use of &#039;PRINT&#039; within a function.</description>
		<content:encoded><![CDATA[<p>Invalid use of &#8216;PRINT&#8217; within a function.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
