Solved

Issue with Select Case

Posted on 2013-06-27
3
497 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A safe way to clean winsxs folder from your windows server 2008 R2 editions
A Short Story about the Best File Recovery Software – Acronis True Image 2017
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

15 Experts available now in Live!

Get 1:1 Help Now