Solved

SQL Server count function

Posted on 2011-09-23
3
273 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 53

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

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…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

752 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