Solved

How to substitute text in the select statement output?

Posted on 2011-09-08
2
230 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 500 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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server Results to Excel File 18 76
MySQL programmer starter 25 32
mysql vs miscrosoft sql server 6 20
Need a mirrored QA test site 2 17
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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