| Author |
Topic |
|
jsmoritz
Starting Member
3 Posts |
Posted - 2009-02-13 : 17:04:22
|
| I have a select statement that reads:SELECT tblStudent.strStuLastName, tblBank.intBankBalanceFROM tblStudent INNER JOINtblBank ON tblStudent.StudentID = tblBank.intBankStuIDWHERE tblStudent.booStuInactive = 0This is my question. Some students are not in tblBank because they haven't received any points yet but I want them included in the query as having a balance of 0. Is there a way to do this? |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-13 : 17:06:49
|
| [code]SELECT tblStudent.strStuLastName, Coalesce(tblBank.intBankBalance,0)as IntBankBalanceFROM tblStudent LEFT OUTER JOINtblBank ON tblStudent.StudentID = tblBank.intBankStuIDWHERE tblStudent.booStuInactive = 0[/code] |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-13 : 17:10:40
|
quote: Originally posted by sodeep
SELECT tblStudent.strStuLastName, Coalesce(tblBank.intBankBalance,0)as IntBankBalanceFROM tblStudent LEFT OUTER JOINtblBank ON tblStudent.StudentID = tblBank.intBankStuIDWHERE tblStudent.booStuInactive = 0
Sorry,Should be:SELECT tblStudent.strStuLastName, Coalesce(tblBank.intBankBalance,0)as IntBankBalanceFROM tblStudent LEFT OUTER JOINtblBank ON tblStudent.StudentID = tblBank.intBankStuIDAND tblStudent.booStuInactive = 0 |
 |
|
|
jsmoritz
Starting Member
3 Posts |
Posted - 2009-02-13 : 17:17:53
|
| Thank you, thank you, thank you!!!!! |
 |
|
|
jsmoritz
Starting Member
3 Posts |
Posted - 2009-02-13 : 17:39:44
|
| It worked great. I have never understood outer joins and now I do. Coalesce is new to me also and will be handy in the future. The statement works great. Thanks again. |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-13 : 17:45:22
|
| You are Welcome. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-02-14 : 01:06:25
|
quote: Originally posted by jsmoritz It worked great. I have never understood outer joins and now I do. Coalesce is new to me also and will be handy in the future. The statement works great. Thanks again.
read this for more infohttp://weblogs.sqlteam.com/jeffs/archive/2007/05/14/60205.aspxhttp://sqlblogcasts.com/blogs/madhivanan/archive/2007/10/04/isnull-or-coalesce.aspx |
 |
|
|
|