January 11, 2016 at 6:43 am
Hi guys,
If i am putting count(any integer) like count (5) .
It will count all the rows of table and showing same result if we change other value stilll resull result is same.
How count work at backend level that i dont understand ?
January 11, 2016 at 7:55 am
Hi
welcome to SSC......
your question isnt clear to me...suggest you read following article and post back.
http://spaghettidba.com/2015/04/24/how-to-post-a-t-sql-question-on-a-public-forum
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
January 11, 2016 at 8:05 am
COUNT(<any constant>) means count the rows in the resultset. If you say COUNT(<any constant>) FROM Table, then it returns count of the rows in the table.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 11, 2016 at 8:06 am
That any integer is just a placeholder. As you've already noticed, you'll get the same result whatever argument you put in there. What you do have to be careful of is putting a column name as an argument. If you do that, you'll get a count of non-null values in that column, which won't necessarily be the same as the number of rows.
John
January 11, 2016 at 10:30 am
Thanks john
January 11, 2016 at 11:23 am
John Mitchell-245523 (1/11/2016)
That any integer is just a placeholder. As you've already noticed, you'll get the same result whatever argument you put in there. What you do have to be careful of is putting a column name as an argument. If you do that, you'll get a count of non-null values in that column, which won't necessarily be the same as the number of rows.John
I would phrase it slightly differently. COUNT() will count the non-null instances of the given expression for each row. Integer constants will never be NULL, so this is equivalent to counting every row.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
January 11, 2016 at 1:09 pm
You've received an explanation on why your code isn't behaving as you expected.
Maybe now you could explain what you're trying to do and get the way to do it correctly.
Unless you're fine with the previous answers.
Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply