|
-
May 31st, 2005, 04:36 AM
#1
Thread Starter
Addicted Member
[RESOLVED] HOW to count records in database??
in my database each doctor has multiple slips (one to many)..i want to cout the total
number of slips for each doctor and display it in the datagrid...in a culomn called
"Uncompleted Slips".. so it will display the total number of slips near the doctor name
How can i do that??
SQL Server 2000
Last edited by NinaWilliam; Mar 8th, 2006 at 02:00 AM.
-
May 31st, 2005, 04:49 AM
#2
Hyperactive Member
Re: HOW to count records in database??
I presume your column is something like
RowNo | Slips
1 5
2 10
3 6
In which case you can simply use
Select Sum(Slips)
FROM yourTable
Which would return a single row with an item containing a value 21 !
Note that this is a normal select statment. Thus you could do
Select Sum(Slips) From yourTable Where Doctor = DoctorID
Hope this helps !
-
Jun 2nd, 2005, 06:33 AM
#3
New Member
Re: HOW to count records in database??
I am assuming
DoctorId SlipId are the collumn name.
U can Get By
Select doctorId,Count(SlipId)
From tableName
Group By
DoctorId
-
Jun 2nd, 2005, 07:18 AM
#4
Re: HOW to count records in database??
Code:
Select DoctorId,Sum(1) From SomeTable Group by DoctorId
Count() does funny things with NULL values - Sum(1) is more intuitive to me.
-
Jun 7th, 2005, 11:23 PM
#5
-
Mar 8th, 2006, 01:59 AM
#6
Thread Starter
Addicted Member
Re: HOW to count records in database??
thanks guys..
-
Mar 8th, 2006, 11:55 AM
#7
Re: HOW to count records in database??
 Originally Posted by szlamany
Count() does funny things with NULL values - Sum(1) is more intuitive to me.
It works, but Sum is more costly than the following, which solves for the same thing:
SELECT COUNT(*) FROM DATABASE WHERE DOCTORID = @ID
COUNT(*) counts rows.
Need to re-register ASP.NET?
C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i
(Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|