?
Solved

How to substitute text in the select statement output?

Posted on 2011-09-08
2
Medium Priority
?
232 Views
Last Modified: 2012-08-14
I have only numeric values in a table.  I want the output of a select statement to show text values rather than the numeric values.  Modifying the table is not an option.  I need to perform the substitution entirely within the select statement.

Select Example:

select period, sum(sales)
from salestable

Desired Output Example:

Apr  23,000
May 50,000


Table Data Example:

Period Sales
4          23,000
5          50,000

The actual data is much more complex, but a solution to the above should do it.  Thanks in advance!
0
Comment
Question by:CPA_MCSE
[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
2 Comments
 
LVL 17

Accepted Solution

by:
Chris Mangus earned 2000 total points
ID: 36503900
Select Case When Period = '4' Then 'Apr'
                     When Period = '5' Then 'May'
                     End As Period,
Sales
From salestable


You can modify the case statement for your other months.
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 36505500


use convert and convert styles
convert(datatype,expression,style)

e.g.

select left(datename(mm,'2001'+right('00'+convert(varchar(2),period),2)+'01'),3) as Period
       ,convert(money,sales,1) as Sales
from (
select period,sum(sales) as sales
from salestable
group by period) as x
order by x.period

Open in new window

0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

752 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