Solved

SQL Server count function

Posted on 2011-09-23
3
269 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
Comment Utility
the first count one column, the second count the entire table
0
 
LVL 51

Accepted Solution

by:
HainKurt earned 500 total points
Comment Utility
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
Comment Utility
Cool! Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now