ASPForums.Net RSS Feed additions to the content that appears on ASPForums.Net(c) 2019 All rights reserved.Count number or record from each Group in SQL Server<p>Hi <a class="username" rel="phonghue">phonghue</a>,</p> <p>Check with the below query.</p> <pre class="brush: sql">SELECT AutoNum,OrgCode,OPTitle,OPPubDescrip,number1,COUNT(number1) AS number,OPMissionS FROM ( SELECT PROGRAMS.AutoNum, PROGRAMS.OrgCode, PROGRAMS.OPTitle, PROGRAMS.OPPubDescrip, CASE WHEN LEN(PROGRAMS.OPPubDescrip) &gt; 700 THEN 2 ELSE 1 END AS number1, PROGRAMS.OPMissionS FROM ORGANIZATIONS INNER JOIN PROGRAMS ON ORGANIZATIONS.OrgCode = PROGRAMS.OrgCode WHERE ORGANIZATIONS.Status = &#39;Approved&#39; AND PROGRAMS.OPStatus = &#39;Active&#39;) t GROUP BY AutoNum,OrgCode,OPTitle,OPPubDescrip,number1,OPMissionS ORDER BY OrgCode</pre> <p>Chack the sample query.</p> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">SELECT Name,number1,COUNT(number1) Number FROM ( SELECT EmployeeID,FirstName + &#39; &#39; + LastName Name, CASE WHEN LEN(CONVERT(VARCHAR(MAX),Notes)) &gt; 200 THEN 2 ELSE 1 END AS number1 FROM Employees)t GROUP BY EmployeeID,Name,number1 ORDER BY EmployeeID</pre> <p><strong><span style="text-decoration: underline;">Output</span></strong></p> <table border="1"> <tbody> <tr> <td><strong>Name</strong></td> <td><strong>number1</strong></td> <td><strong>Number</strong></td> </tr> <tr> <td>Nancy Davolio</td> <td>1</td> <td>1</td> </tr> <tr> <td>Andrew Fuller</td> <td>2</td> <td>1</td> </tr> <tr> <td>Janet Leverling</td> <td>2</td> <td>1</td> </tr> <tr> <td>Margaret Peacock</td> <td>2</td> <td>1</td> </tr> <tr> <td>Steven Buchanan</td> <td>2</td> <td>1</td> </tr> <tr> <td>Michael Suyama</td> <td>2</td> <td>1</td> </tr> <tr> <td>Robert King</td> <td>2</td> <td>1</td> </tr> <tr> <td>Laura Callahan</td> <td>1</td> <td>1</td> </tr> <tr> <td>Anne Dodsworth</td> <td>1</td> <td>1</td> </tr> </tbody> </table> <p>&nbsp;</p>, 14 Aug 2019 04:20:06 GMT