thursdaysgeek
thursdaysgeek

Reputation: 7946

How do I change the value in a SQL Server view?

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?

Upvotes: 0

Views: 5199

Answers (2)

John Hartsock
John Hartsock

Reputation: 86882

Create View Test_View
As
   Select 
      t1.Id   as 'Id'
     , CASE WHEN t2.Flag = 1 THEN
          'Yes'
       ELSE
           'No'
       END as 'IsChecked'

Upvotes: 1

dcp
dcp

Reputation: 55454

CASE
  WHEN t1.Id = 1 THEN 'Yes'
  WHEN t1.Id = 0 THEN 'No'
End as 'IsChecked'

Upvotes: 4

Related Questions