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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-04-29 : 07:38:05
|
| Alex writes "Can a query be created that will check to see whether a column (B) is null (has no data)? If no data, select columns A,C,D. If data exists in column B, select columns A,B,C,D" |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-04-29 : 07:50:42
|
what do you mean by that?? i can't really visualize what you mean.do you want do check all values in column B?select A, isnull(B, ''), C, Dfrom MyTableGo with the flow & have fun! Else fight the flow |
 |
|
|
KLang23
Posting Yak Master
115 Posts |
Posted - 2005-04-29 : 14:55:36
|
| Select Case When B is NULL Then A End Else B as ColA Case When B is NULL Then B End Else NULL as ColB Case When B is NULL Then C End Else NULL as ColCFrom TableXIf the columns are of different types (int vs. char) you will have to convert one of them (int) to the type of the other (char).Case When B is NULL Then Convert(Varchar(5),A) End Else B as ColABest of luck,Kevin |
 |
|
|
KLang23
Posting Yak Master
115 Posts |
Posted - 2005-04-29 : 14:57:44
|
| OOps - syntax check - place the "End" after the "Else" ie:SelectCase When B is NULL Then A Else B End as ColACase When B is NULL Then B Else NULL End as ColBCase When B is NULL Then C Else NULL End as ColCFrom TableXCheers,Kevin |
 |
|
|
|
|
|
|
|