Solved

Issue with Select Case

Posted on 2013-06-27
3
532 Views
Last Modified: 2013-07-01
Hi Experts,


select distinct
        CASE WHEN TRIM(Cast(decile as varchar(3))) =''  THEN 'U'
        ELSE Trim(Cast(decile as varchar(3))) END  decile
from Table1
where model_name = 'TopTier'

Note : decile is tinyint of length 3 in table 1

I want this select statement to return 'U' as there are no records for model name :TopTier in table 1.

But this statement is returning 0 records. Please correct this statment.

Thanks ,

SAI
0
Comment
Question by:n_srikanth4
[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 Comments
 
LVL 6

Accepted Solution

by:
Dulton earned 500 total points
ID: 39282109
Try this.

;with Tbl1 AS
(
SELECT decile
FROM Table1
WHERE model_name = 'TopTier'
)
select distinct
        CASE WHEN TRIM(Cast(decile as varchar(3))) =''  THEN 'U'
        ELSE Trim(Cast(decile as varchar(3))) END  decile
from Tbl1
union select 'U'
where not exists (select decile from Tbl1)
0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 39283098
This should work.
select 'U' where not exists (select decile from Table1 where model_name = 'TopTier')
union
select distinct
        CASE WHEN TRIM(Cast(decile as varchar(3))) =''  THEN 'U'
        ELSE Trim(Cast(decile as varchar(3))) END  decile
from Table1
where model_name = 'TopTier'

Open in new window

0
 

Author Closing Comment

by:n_srikanth4
ID: 39290045
good
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

Suggested Solutions

While it may be true that the internet is a place of possibilities, it is also a hostile environment lurking with many dangers. By clicking on the wrong link, trusting the wrong person or using a weak password, you are virtually inviting hackers to …
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

756 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