Solved

SQL Server count function

Posted on 2011-09-23
3
272 Views
Last Modified: 2012-05-12
Hi experts,

I can't tell the difference between these two selects, could you help me understand why they would behave differently?

1. select process_Step, loan_status, count(acct#) from LMDev.dbo.sd10_View_Staging group by process_step, loan_status

2. select process_Step, loan_status, count(*) from LMDev.dbo.sd10_View_Staging group by process_step, loan_status

Thanks!
0
Comment
Question by:JC_Lives
3 Comments
 
LVL 8

Expert Comment

by:Crashman
ID: 36589960
the first count one column, the second count the entire table
0
 
LVL 51

Accepted Solution

by:
Huseyin KAHRAMAN earned 500 total points
ID: 36589993
check this sample

count(col) counts not null records
count(*) = count(1) counts all rows
a    b
---------
null 1
2    null
null 3

with c as (
select null a, 1 b
union select 2, null
union select null, 3)
select count(a), count(b), COUNT(*), COUNT(1) from c

1	2	3	3

Open in new window

0
 

Author Closing Comment

by:JC_Lives
ID: 36590005
Cool! Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question