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 |
|
Harry C
Posting Yak Master
148 Posts |
Posted - 2005-04-20 : 10:43:00
|
| I have a table as followsNotebookID int 4 (PK)PersonID int 4KnowledgeBaseID int 4DiscussionThreadID int 4[FreeText] varchar 500CourseID int 4NotebookEntryDate datetime 8In this table, the KnowledgeBaseID, DiscussionThreadID or FreeText can be NULL. So, what I want to do is the in ONE statement (preferably) select what is NOT null.So, I want say basically "Get back KnowledgeBaseID If DiscussionThreadID AND FreeText are NULL" OR "Get back DiscussionThreadID If KnowledgeBaseID AND FreeText are NULL" OR "Get back FreeText If KnowledgeBaseID AND DiscussionThreadID are NULL"WHERE NotebookID = @NotebookID...I know this is simple, and I am making it complex. That is why I am asking for help writing the statement! Thanks in advance for any guidance!Harry C |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2005-04-20 : 10:47:04
|
| What if more than one condition applies?Anyway, you can use the CASE statement to achieve what you want to do.SELECT CASE when blah is null and blah2 is null then blah3 CASE when blah2 is null and blah3 is null then blahEND AS yourvalue from yourtable-------Moo. :) |
 |
|
|
Harry C
Posting Yak Master
148 Posts |
Posted - 2005-04-20 : 12:17:37
|
| Your right! This minor tweak solves that problem. Thanks alotSELECT (CASE WHEN KnowledgeBaseID IS NOT NULL then 'Test' WHEN DiscussionThreadID IS NOT NULL then 'Test' WHEN [FreeText] IS NOT NULL then 'It worked!'END) AS NotebookDisplayName FROM NotebookWHERE NotebookID = @NotebookID |
 |
|
|
|
|
|