[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

IF / ELSE and REPLACE in view creation?

I am creating a view and would like to display something like the following...

If field equals XXX then print 'FOO', else print 'BAR'

... as a new field in the view.

New to T-SQL, thanks in advance for any pointers...
0
AndyWF
Asked:
AndyWF
1 Solution
 
LowfatspreadCommented:
the clause you are looking for is the case statement...

select  case when field = 'xxx' then foo else bar end as mycolumnname
from ....

two forms are available for the case statement...
case when expression = expression then expression
        when expression1 condition expression2 then expression3
        else expression4
        end

or

case expression
        when value/expression   then expression
        when ....
        else expression
        end
       
0
 
AndyWFAuthor Commented:
Thank you!  That got me exactly where I needed to be...
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now