Solved

Issue with Select Case

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

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Part Two of the two-part Q&A series with MalwareTech.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 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