﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Christoffer Hedgate / Article Discussions / Article Discussions by Author  / Advice on using COUNT( ) / 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>Mon, 20 May 2013 06:32:53 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Advice on using COUNT( )</title><link>http://www.sqlservercentral.com/Forums/Topic6965-94-1.aspx</link><description>Hi Chris Excellent. Thanks a lot for change my concepts about count(*) and count(Column Name). I also belive Count(ColumnName) is working best. But your article changes my concept.Again thank you very much.virgo.neelaya@gmail.com</description><pubDate>Wed, 15 Apr 2009 02:34:15 GMT</pubDate><dc:creator>neelaya_patnaik</dc:creator></item><item><title>RE: Advice on using COUNT( )</title><link>http://www.sqlservercentral.com/Forums/Topic6965-94-1.aspx</link><description>&lt;P&gt;From the main screen, click on [Resources][Discussion Forums].  You will be taken to a screen with different forums.  The T-SQL forum seems to be the most popular but take the time to scan the list to find the most appropriate forum.  Then, click on that forum and you will be taken to that forum.  Near the top of the window is a "button" to start a new thread... click on it and type your question.&lt;/P&gt;&lt;P&gt;Remember to include information about any tables you have (column names, datatype, etc) for the columns required to solve you problem.  Also, include some sample data and what you'd like the output to look like as well as a description of what process you'd like to follow to get to that output.  &lt;/P&gt;</description><pubDate>Thu, 11 May 2006 23:54:00 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Advice on using COUNT( )</title><link>http://www.sqlservercentral.com/Forums/Topic6965-94-1.aspx</link><description>&lt;P&gt;Something like this, I would imagine...&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt; SELECT (--Finds count of ALL distinct machine names in the table         SELECT COUNT(DISTINCT MachineName)           FROM yourtable        )      - (--Finds count of distinct machine names updated in last 14 days         SELECT COUNT(DISTINCT MachineName)            FROM yourtable          WHERE TimeUpdated &amp;gt;= GETDATE()-14        )        AS MachinesNotUpdatedLast14&lt;/FONT&gt;&lt;/P&gt;</description><pubDate>Thu, 11 May 2006 23:45:00 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: Advice on using COUNT( )</title><link>http://www.sqlservercentral.com/Forums/Topic6965-94-1.aspx</link><description>How can i use count in a statement to just find the total count of computers that havent been updated in the past 14 days? I have 21,000 endpoints in the system and i have a existing query that finds all the machines listed by machine name and time updated?</description><pubDate>Thu, 11 May 2006 20:31:00 GMT</pubDate><dc:creator>Bradley Clark</dc:creator></item><item><title>RE: Advice on using COUNT( )</title><link>http://www.sqlservercentral.com/Forums/Topic6965-94-1.aspx</link><description>&lt;P&gt;Can I introduce a new topic myself in the forum to seek some advice on?&lt;/P&gt;&lt;P&gt;Sorry I have just joined and can not find it how to post a new topic.&lt;/P&gt;</description><pubDate>Mon, 14 Feb 2005 12:07:00 GMT</pubDate><dc:creator>S Javed</dc:creator></item><item><title>RE: Advice on using COUNT( )</title><link>http://www.sqlservercentral.com/Forums/Topic6965-94-1.aspx</link><description>Chris it is DBCC UPDATEUSAGE.&lt;BLOCKQUOTE id=quote&gt;&lt;font size=1 face="Verdana, Arial, Helvetica" id=quote&gt;quote:&lt;hr height=1 noshade id=quote&gt;Specifies that the rows column of sysindexes is updated with the current count of the number of rows in the table or view. This applies only to sysindexes rows that have an indid of 0 or 1. This option can affect performance on large tables and indexed views.&lt;hr height=1 noshade id=quote&gt;&lt;/BLOCKQUOTE id=quote&gt;&lt;/font id=quote&gt;&lt;font face="Verdana, Arial, Helvetica" size=2 id=quote&gt;However 2000 seems to be a little less troublesome about this issue. 7 was and to my knowledge even with SP4 is still notorious for incorrect values.Good article."Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)Edited by - antares686 on 09/24/2002  04:06:27 AM</description><pubDate>Tue, 24 Sep 2002 04:05:00 GMT</pubDate><dc:creator>Antares686</dc:creator></item><item><title>RE: Advice on using COUNT( )</title><link>http://www.sqlservercentral.com/Forums/Topic6965-94-1.aspx</link><description>Thanks for the input guys.Scott: Yes, they result in the exact same behaviour and execution plan. SQL uses the best index available to it.Greg: Absolutely, the fastest way of getting the number of rows is querying the sysindexes table about it. It's just that you can't be sure of this number being properly updated at any given time. I'm not 100% sure of this, but I think you can force SQL to update this value to make sure it is correct by running UPDATE STATISTICS. Also, use the column rowcnt instead of rows, rows is only there for backward compatibility.Chris Hedgate @ Apptus Technologies (http://www.apptus.se)http://www.sql.nu</description><pubDate>Mon, 23 Sep 2002 08:33:00 GMT</pubDate><dc:creator>Chris Hedgate</dc:creator></item><item><title>RE: Advice on using COUNT( )</title><link>http://www.sqlservercentral.com/Forums/Topic6965-94-1.aspx</link><description>Good article.  Has a lot of valuable information about the in's and out's of COUNT.  I've always used code similar to this for finding the row count, provided there is a clustered index.SELECT ROWS FROM SYSINDEXES WHERE OBJECT_ID('ORDERS') = ID AND INDID &amp;lt; 2  This command only does "2" logical reads, so I'm guessing it performs, slightly better then select count(*) from orders.  Gregory Larsen, DBAIf you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples</description><pubDate>Mon, 23 Sep 2002 08:08:00 GMT</pubDate><dc:creator>Greg Larsen</dc:creator></item><item><title>RE: Advice on using COUNT( )</title><link>http://www.sqlservercentral.com/Forums/Topic6965-94-1.aspx</link><description>I usually code this as count(1) rather than count(*).  I'm not sure why, I have just been doing it for years.  It seems to do the same thing - same number of logical reads in the tests I have run.  Any pros or cons to this style?Scott Stonehouse</description><pubDate>Mon, 23 Sep 2002 06:42:00 GMT</pubDate><dc:creator>ScottStonehouse</dc:creator></item><item><title>Advice on using COUNT( )</title><link>http://www.sqlservercentral.com/Forums/Topic6965-94-1.aspx</link><description>Comments posted to this topic are about the content posted at &lt;A HREF=http://www.sqlservercentral.com/columnists/chedgate/adviceoncount.asp&gt;http://www.sqlservercentral.com/columnists/chedgate/adviceoncount.asp&lt;/A&gt;</description><pubDate>Sun, 22 Sep 2002 00:00:00 GMT</pubDate><dc:creator>Chris Hedgate</dc:creator></item></channel></rss>