to use aggregate function with other columns | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

to use aggregate function with other columns

MS SQL does not support to use aggregate function along with other Columns even if we have GROUP BY clause.<br />like…<br />SELECT &lt;SomeField&gt;, Count(&lt;FieldName&gt<img src=’/community/emoticons/emotion-5.gif’ alt=’;)‘ /> FROM &lt;TableName&gt; WHERE &lt;SomeCondition&gt;
That should be<br /><br />SELECT &lt;SomeField&gt;, Count(&lt;FieldName&gt<img src=’/community/emoticons/emotion-5.gif’ alt=’;)‘ /> FROM &lt;TableName&gt; WHERE &lt;SomeCondition&gt;<br />group by &lt;SomeField&gt;<br /><br />Madhivanan<br /><br />Failing to plan is Planning to fail
Is this a question or what are you trying to achieve? —
Frank Kalis
Microsoft SQL Server MVP
http://www.insidesql.de
Heute schon gebloggt?http://www.insidesql.de/blogs

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by harleen</i><br /><br />MS SQL does not support to use aggregate function along with other Columns even if we have GROUP BY clause.<br />like…<br />SELECT &lt;SomeField&gt;, Count(&lt;FieldName&gt<img src=’/community/emoticons/emotion-5.gif’ alt=’;)‘ /> FROM &lt;TableName&gt; WHERE &lt;SomeCondition&gt;<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br /><br />I am not too sure about the issue that you are come upwith.<br />anyway, one way is use Having if possible and the other is use sub query<br /><br />—————————————-<br /<a target="_blank" href=http://spaces.msn.com/members/dineshasanka>http://spaces.msn.com/members/dineshasanka</a><br />
>>anyway, one way is use Having if possible and the other is use sub query Having can be used only if Group by is used Madhivanan Failing to plan is Planning to fail
yes I coundn’t mentioned that. Thanks Madhivanan. —————————————-
http://spaces.msn.com/members/dineshasanka

]]>