I want to make view or simply to get some data from database but in specific way.
For example if data is :
1 | test | test | 0 | test
2 | test | test | 1 | test
3 | test | test | 1 | test
4 | test | test | 1 | test
5 | test | test | 0 | test
The output should be:
1 | test | test | FALSE | test
2 | test | test | TRUE | test
3 | test | test | TRUE | test
4 | test | test | TRUE | test
5 | test | test | FALSE | test
Any ideas?
Use CASE expression.
Query
SELECT col1, col2, col3,
CASE col4 WHEN 0 THEN 'False'
WHEN 1 THEN 'TRUE'
ELSE NULL END AS col4, col5
FROM your_table_name;
An if condition in SQL is expressed using CASE expression:
SELECT
id
, a
, b
, CASE c WHEN 0 THEN 'FALSE' ELSE 'TRUE' END AS c
, d
FROM my_table
Note that there are two forms of CASE expression in SQL Server - simple and searched. The above is an example of a simple.
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