Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Server count function

Posted on 2011-09-23
3
Medium Priority
?
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Expert Comment

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

705 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