S
S
sorry_i_noob2019-06-11 13:44:02
SQL
sorry_i_noob, 2019-06-11 13:44:02

Is it possible to create such a query in SQL in which numbers are replaced with text?

Hello. I have a table that has some values ​​(orders) and their status (integer value). I want to create a request where the status will change to text.
More or less like this.
0 - will be replaced with "work not started".
1 - "work in progress".
2 - "work done".
Is it possible to write such a query in SQL? Or you need to create two tables - orders and statuses. And to make a query based on these tables?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
mletov, 2019-06-11
@sorry_i_noob

SELECT (CASE
                  WHEN stat=0
                  THEN 'работа не начата'
                  WHEN stat=1
                  THEN 'работа идет'
                  WHEN stat=2
                  THEN 'работа выполнена'
             END) AS statStr
FROM table

In general, it's better
and do through JOIN
t to
1) CASE WHEN can reduce the performance of the query
2) The status directory can be replenished and you will have to update the query all the time

R
Ruslan Ruslanov, 2019-06-11
@dasauser

yes, you can.

K
Konstantin Tsvetkov, 2019-06-11
@tsklab

SELECT ProductName, Manufacturer,
    CASE ProductCount
        WHEN 1 THEN 'Товар заканчивается'
        WHEN 2 THEN 'Мало товара'
        WHEN 3 THEN 'Есть в наличии'
        ELSE 'Много товара'
    END AS EvaluateCount
FROM Products

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question