Solved

cae and select together

Posted on 2009-07-13
5
176 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
  • 3
5 Comments
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 350 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 150 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 150 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Authentication error 1 38
INSERT DATE FROM STRING COLUMN 18 49
Access 2010 Query Syntax 5 21
Replace Dates in query 14 11
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now