Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Testing two columns for one being unknown

How can I identify the rows in this sample, where only one of the columns is "Unknown"?

  • If both columns are the same, but not unknown, that’s great – use either
  • If one is unknown and the other column is not, that’s also great – use the other.
  • If they are both unknown, that’s a problem easily managed

Putting a heap of nested if then type clauses doesn’t sound like the smartest way to do it.

Using SQL Server 11x

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sample

>Solution :

You could use:

SELECT ROW, ID, Name,
       CASE WHEN Test1 = 'Unknown' THEN Test2 ELSE Test1 END AS Test
FROM yourTable;

This will report in Test the value of Test1 if not unknown, otherwise the value of Test2. In the case of both being unknown, it would report unknown.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading