Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a Table with a CheckIn and CheckOut Fileds.
I want to Count a Total Attempt..

The Entrys will be like this..
SQL
CheckIn                      CheckOut
2011-09-29 17:27:59.653      2008-11-29 17:35:50.020
NULL                         2008-11-29 18:07:49.653
2008-11-29 17:27:59.653      NULL


When I try to count total attempt like
SQL
SELECT COUNT(CheckIn) From Attendance

Then it will be Resulted in Only 2

But actually my Requirement is that even if CheckIn is null and the CheckOut filed is contain any entry then it will be counted

so when i fire a query for counting total attempt then it will be resulted in 3 on above data..


Thanks in Advance..
Tejas Vaishnav
Posted

Null values are not counted as entries - understandably - so the COUNT function ignores them.
Instead use '*':
SQL
SELECT COUNT(*) FROM Attendance
 
Share this answer
 
Comments
Tejas Vaishnav 1-Oct-11 4:18am    
Thats why i ask a question..
Dear
Try this code.

SELECT COUNT(CheckIn) From Attendance where CheckIn is not null

SELECT COUNT(CheckOut) From Attendance where Checkout is not
null
 
Share this answer
 
v2
You can use is null clause for checking

null value existence in table column or any variable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900