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 |
sqlfresher2k7
Aged Yak Warrior
623 Posts |
Posted - 2014-12-27 : 20:46:58
|
[code]Please help to rewrite the below query to get the expected output..I want the description if exist for student to be 1 else 0..Query-------Select StudentNo,Name,Science,Social,MathFrom StudentInfo Sinfo Left Join StudentDesc SDescOn Sinfo.StudentNo = SDesc.StudentNowhere SDesc.Desc in ('Science','Social','Math') Table:StudentInfoStudentNo Name-------- -------1234 Sam1235 Brad1236 Viv 1237 Brigg1241 SimTable:StudentDescStudentNo Desc--------- -----1234 Science1235 Social1236 Science 1237 Math1238 Math1239 English1240 EnglishExpected output==================StudentNo Name Science Social Math-------- ------- -------- ------- ------ 1234 Sam 1 0 01235 Brad 0 1 01236 Viv 1 0 11237 Brigg 0 0 11241 Sim 0 0 0 [/code] |
|
sqlteamsam
Starting Member
1 Post |
Posted - 2014-12-28 : 06:37:04
|
pls try thisSelect StudentNo,Name, case when Science is null then 0 else 1 end ,case when Social is null then 0 else 1 end,case when Math is null then 0 else 1 end,From StudentInfo Sinfo Left Join StudentDesc SDescOn Sinfo.StudentNo = SDesc.StudentNowhere SDesc.Desc in ('Science','Social','Math') |
|
|
|
|
|