Using a CASE statement in SQL Server 2008 R2

I am trying to construct a CASE statement in my query and not sure how to do. I know how to construct it in a normal condition but I have multiple conditions to check for. I have a column, "profileType" that will contain either a "D", "R" or "".

When "profileType" contains "D", it needs to return "Default. If it contains "R", it needs to return "Recent". If it contains "", just return "".
BlakeMcKennaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Radha MConnect With a Mentor Commented:
Use this. Hope you want to include it in your SELECT clause.
SELECT
   col1,
   col2,
   CASE
      WHEN profileType = 'R'
         THEN 'Recent'
      WHEN profileType = 'D'
         THEN 'Default'
      ELSE ''
   END as col3
FROM
   ---

Open in new window

0
 
13598Commented:
Use a nested IIF statement:

iif(profileType = 'D', 'Default',iif(profileType = 'R', 'Recent',''))
0
 
BlakeMcKennaAuthor Commented:
Are you saying insert this statement into the SQL Query? If so, can you be a little more specific in the syntax?

Thanks!
0
 
BlakeMcKennaAuthor Commented:
That worked!

Thanks!
0
All Courses

From novice to tech pro — start learning today.