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 2000 Forums
 Transact-SQL (2000)
 CASE statement

Author  Topic 

koln5
Starting Member

29 Posts

Posted - 2004-09-14 : 12:58:30
Mycolumn is datatype nvarchar (255)

I want another column created called 'Available' based on data present in Mycolumn

The type of data found in Mycolumn is either 'NULL' or 'NO' or a something else ('E16', 'wearhouse', etc)

So now I want to write my CASE statement that says, if Mycolumn has a value of NULL or NO, then insert a 'NO' in a new column called 'Available', otherwise insert a 'YES' into the Available column. But when I write the below syntax, only 'YES' is inserted in every row in my Available column, even when the value in Mycolumn is NULL or No....why is that ?

Thank you

Available = (CASE dbo.mydatabase.Mycolumn WHEN NULL THEN 'No' WHEN 'No' THEN 'NO' ELSE 'YES' END)

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-14 : 13:01:13
try this:
Update MyTable
set Available = (CASE WHEN dbo.mydatabase.Mycolumn is NULL or dbo.mydatabase.Mycolumn = 'No 'THEN 'NO' ELSE 'YES' END)
from...
where...

Go with the flow & have fun! Else fight the flow
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2004-09-14 : 13:15:51
Isn't it mydatabase.dbo.Mycolumn ?
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-14 : 13:27:09
i took that as a typo. i think he meant dbo.MyTableName.MyColumn.
if it's not a typo it should be: mydatabase.dbo.MyTable.Mycolumn

Go with the flow & have fun! Else fight the flow
Go to Top of Page

koln5
Starting Member

29 Posts

Posted - 2004-09-14 : 16:09:15
You guys are both correct...and your syntax worked....THANK YOU Spirit1
Go to Top of Page
   

- Advertisement -