I need to add characters to values in a column. For example:
Price column
22.99
12.95
10.35
For my query output, I need this column to show as
Price column
Price is 22.99
Price is 12.95
Price is 10.35
I already used this to convert these values to char as I think I have to do this to insert characters in this column...
CONVERT (char(12), price) AS price
I just can't figure out how I can write the command to add "Price is" in every row :(
Please help, thank you!
You cannot permanently to do this if the data type of the column is INT
or number but you can do it on SELECT
statement,
In MySQL
:
SELECT CONCAT('Price is ', priceColumn) Price_Column
FROM tableName
In TSQL
SELECT 'Price is ' + CAST(priceColumn AS VARCHAR(15)) Price_Column
FROM tableName
But if you change the data type of that column into string (VARCHAR()
) then you can simple execute UPDATE
command
In MySQL
,
UPDATE tableName
SET priceColumn = CONCAT('Price is ', priceColumn)
in TSQL
UPDATE tableName
SET priceColumn = 'Price is ' + CAST(priceColumn AS VARCHAR(15))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With