Solved

Adding Extra Characters to query output

Posted on 2011-03-20
4
293 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:greeneel
  • 2
4 Comments
 
LVL 12

Assisted Solution

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

Assisted Solution

by:Aaron Tomosky
Aaron Tomosky earned 100 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 150 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 250 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Loading csv or delimited data files to MySQL database is a very common task frequently questioned about and almost every time LOAD DATA INFILE comes to the rescue. Here we will try to understand some of the very common scenarios for loading data …
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

758 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

25 Experts available now in Live!

Get 1:1 Help Now