Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding Extra Characters to query output

Posted on 2011-03-20
4
Medium Priority
?
300 Views
Last Modified: 2012-06-27
Hey guys,

I would like to find out how to add text to the starting and/or the end of a column output.....


query example --
SELECT price, category, item_image
FROM table_name

before --
9.99, electronic_item, item_image.jpg

after --
9.99, electronic_item, item_image_90.jpg

What I'm looking for is to have for e.g "_90" suffixed or put in behind of all image records that are produced from the query results..
0
Comment
Question by:Eaddy Barnes
  • 2
4 Comments
 
LVL 12

Assisted Solution

by:Amick
Amick earned 1000 total points
ID: 35177283
SELECT price, category, item_image||'_90'
FROM table_name
0
 
LVL 39

Assisted Solution

by:Aaron Tomosky
Aaron Tomosky earned 400 total points
ID: 35177297
The end of a string is easy. Select image_name+'_90' from table
The harder part is to insert it before the .jpg. Using left and search it can be done. You can also do replace to replace .jpg with _90.jpg
0
 
LVL 2

Accepted Solution

by:
michael_madsen earned 600 total points
ID: 35177300
This query:

SELECT price, category, item_image+'_90'
FROM table_name

will add '_90' to all values in [item_image] field, but if you have the field values to be: 'item_image.jpg', the result would be: 'item_image.jpg_90', which isn't what you want.

What you could do is:

SELECT price, category, replace(item_image, '.jpg', '_90.jpg')
FROM table_name
0
 
LVL 12

Assisted Solution

by:Amick
Amick earned 1000 total points
ID: 35177323
This is the MySQL way to do it:

SELECT price, category, concat(item_image,'_90')
FROM table_name 

Open in new window


The SQL Server / Microsoft Access way
SELECT price, category, item_image+'_90'
FROM table_name 

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
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…
Suggested Courses
Course of the Month10 days, 3 hours left to enroll

927 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