• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

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 "".
0
BlakeMcKenna
Asked:
BlakeMcKenna
  • 2
1 Solution
 
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
 
Radha MCommented:
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
 
BlakeMcKennaAuthor Commented:
That worked!

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

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