Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using a CASE statement in SQL Server 2008 R2

Posted on 2014-09-04
4
Medium Priority
?
297 Views
Last Modified: 2014-09-04
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
Comment
Question by:BlakeMcKenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 16

Expert Comment

by:13598
ID: 40304192
Use a nested IIF statement:

iif(profileType = 'D', 'Default',iif(profileType = 'R', 'Recent',''))
0
 

Author Comment

by:BlakeMcKenna
ID: 40304207
Are you saying insert this statement into the SQL Query? If so, can you be a little more specific in the syntax?

Thanks!
0
 
LVL 1

Accepted Solution

by:
Radha M earned 2000 total points
ID: 40304210
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
 

Author Closing Comment

by:BlakeMcKenna
ID: 40304221
That worked!

Thanks!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question