snippetsqlMajor
How to append value of column with double quotes (add quotes around string)
Viewed 0 times
aroundcolumnwithvaluequotesdoublehowappendstringadd
Problem
I have a table with a column that is TEXT type. In the column are numeric characters. What I'm trying to achieve is to wrap those characters in double quotes.
EXAMPLE:
IDEAL OUTPUT:
I attempted to run the following SELECT statement but it didn't give me the result I was expecting. Perhaps you can guide me in the right direction?
Thank You
EXAMPLE:
NAME ID QTY
Apples A1 1
Oranges O1 1
Foo F1 0IDEAL OUTPUT:
NAME ID QTY
Apples A1 "1"
Oranges O1 "1"
Foo F1 "0"I attempted to run the following SELECT statement but it didn't give me the result I was expecting. Perhaps you can guide me in the right direction?
SELECT `qty`, CHAR('"'|| qty ||'"')
FROM `myTable`;Thank You
Solution
Use the CONCAT function
If you want single quotes, use the QUOTE function
Give it a Try !!!
SELECT NAME,ID,CONCAT('"',QTY,'"') QTY FROM `myTable`;If you want single quotes, use the QUOTE function
SELECT NAME,ID,QUOTE(QTY) QTY FROM `myTable`;Give it a Try !!!
Code Snippets
SELECT NAME,ID,CONCAT('"',QTY,'"') QTY FROM `myTable`;SELECT NAME,ID,QUOTE(QTY) QTY FROM `myTable`;Context
StackExchange Database Administrators Q#74366, answer score: 21
Revisions (0)
No revisions yet.