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.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Query

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2015-02-21 : 09:29:08
I need a query to get non null value..I can do with case statement but I want to know if IIF,Coalesce or CHOOSE will work.

Student
-------


Sno Subject1 Subject2
--- ------- -------
1 English Null
2 Null Science
3 Social NUll


Expected Results:
-----------------
Sno Subject1
--- -------
1 English
2 Science
3 Social



Note:Each record for the subject1 and subject2 will have One Null and a value but it cannot have both Values..

Thanks for your help in advance..

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-02-21 : 09:32:11
what if both subjects have values?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2015-02-22 : 11:49:44
SELECT sNo, COALSCE(Subject1, Subject2)
FROM dbo.Sample


Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

viggneshwar
Yak Posting Veteran

86 Posts

Posted - 2015-02-24 : 04:41:37
SELECT sNo, isnull(Subject1, Subject2)
FROM dbo.Sample

Regards
Viggneshwar A
Go to Top of Page
   

- Advertisement -