4

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!

4

1 に答える 1

9

列のデータ型がINTまたは数値SELECTの場合、これを永続的に行うことはできませんが、ステートメントで行うことはできます。

MySQL

SELECT  CONCAT('Price is ', priceColumn) Price_Column
FROM    tableName

TSQL

SELECT  'Price is ' + CAST(priceColumn AS VARCHAR(15)) Price_Column
FROM    tableName

ただし、その列のデータ型を文字列()に変更すると、コマンドVARCHAR()を簡単に実行できますUPDATE

ではMySQL

UPDATE  tableName
SET     priceColumn = CONCAT('Price is ', priceColumn)

TSQL

UPDATE  tableName
SET     priceColumn = 'Price is ' + CAST(priceColumn AS VARCHAR(15))
于 2013-02-24T09:50:06.787 に答える