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

x
?
Solved

cae and select together

Posted on 2009-07-13
5
Medium Priority
?
191 Views
Last Modified: 2012-05-07
is it possible to use CASE and select together... For example

select CASE WHEN @Spec_Desc = 'All' THEN

(SELECT     ID from TBL) ELSE .............
0
Comment
Question by:Mr_Shaw
[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
  • 3
5 Comments
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 1400 total points
ID: 24839186
Sure..
You can use it like that and an example below.
Make sure that SELECT statement is enclosed in braces to work.
DECLARE @a int;
SET @a = 1;
SELECT CASE WHEN @a = 1 THEN (SELECT 'Pass') ELSE (SELECT 'Fail') END 

Open in new window

0
 
LVL 31

Expert Comment

by:RiteshShah
ID: 24839191
you can't have "SELECT" statement in CASE THEN statement. CASE THAN should be nested in SELECT.
0
 
LVL 31

Assisted Solution

by:RiteshShah
RiteshShah earned 600 total points
ID: 24839210
I am sorry, disregard my previous answer, you can use select but it shouldn't return more than one value and there shouldn't be more than one column in select, you can use TOP 1 clause.
0
 
LVL 31

Assisted Solution

by:RiteshShah
RiteshShah earned 600 total points
ID: 24839216
something like this:

DECLARE @a int;
SET @a = 1;
SELECT CASE WHEN @a = 1 THEN (SELECT Top 1 ID from tbl where name='anything') ELSE (SELECT 'Fail') END

0
 

Author Closing Comment

by:Mr_Shaw
ID: 31602799
thanks
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

688 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