Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Server count function

Posted on 2011-09-23
3
Medium Priority
?
279 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 61

Accepted Solution

by:
HainKurt earned 2000 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

Technology Partners: 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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

877 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