Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
abhi123
Starting Member
10 Posts |
Posted - 2009-05-28 : 12:35:46
|
Hi i am new in sql. what i am doing is couting grades. For a paticular course of a student i am counting his/her grade. For simplicity grade can be either P or F. The data i have it is possible that a student would not get any grade for that course. So when i put count on that student for which he didn't get the grade query display null value. Is there any way that null can be replaced with 0. student_name gradesA P BC FD PE F P so B and E the system will display null but i want it 0..Thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-28 : 12:43:44
|
| [code]SELECT student_name,count(*)FROM TableGROUP BY sudent_name[/code] |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-05-28 : 12:50:33
|
| Your question says "count" of grades but your sample shows the actual grade values (P and F). Visakh16's solution will show what you asked for. But to display a replacement for NULL you can use the isnull function: isNull(grades, '0') as gradesBe One with the OptimizerTG |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-28 : 13:13:36
|
| or COALESCE(grades, 0)i gave count(*) as in fact what you want is to count null grades also i.e just number of occurance of a particular student_name in tablebut strictly speaking the answer to your question is ISNULL(grades, 0) or COALESCE(grades, 0) |
 |
|
|
abhi123
Starting Member
10 Posts |
Posted - 2009-05-28 : 13:16:48
|
| Thanks |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-28 : 13:18:43
|
| welcome |
 |
|
|
|
|
|