views:

22

answers:

2

I have a view assembling data from various tables:

Create View Test_View
As
   Select 
      t1.Id   as 'Id'
     ,t2.Flag as 'IsChecked'

etc. In the previous versions of this table, that Flag value had the values 'Yes' and 'No', and now it has been changed to bools, like it should be.

However, the application that uses this view needs to see the 'Yes' and 'No' values, not 1 and 0. What is the syntax for changing that view to return the string 'Yes' if t2.Flag is 1 and 'No' if t2.Flag is 0?

+4  A: 
CASE
  WHEN t1.Id = 1 THEN 'Yes'
  WHEN t1.Id = 0 THEN 'No'
End as 'IsChecked'
dcp
+2  A: 
Create View Test_View
As
   Select 
      t1.Id   as 'Id'
     , CASE WHEN t2.Flag = 1 THEN
          'Yes'
       ELSE
           'No'
       END as 'IsChecked'
John Hartsock
This was also helpful, because the ELSE is good to see. But since a NULL is also an option, assigning both the 1 and 0 was necessary. I didn't say that, however.
thursdaysgeek