In my database (MySQL) table, has a column with 1
and 0
for represent true
and false
respectively.
But in SELECT
, I need it replace for true
or false
for printing in a GridView.
How to I make my SELECT
query to do this?
In my current table:
id | name | hide 1 | Paul | 1 2 | John | 0 3 | Jessica | 1
I need it show thereby:
id | name | hide 1 | Paul | true 2 | John | false 3 | Jessica | true
The Replace statement is used to replace all occurrences of a specified string value with another string value. The Replace statement inserts or replaces values in a table. Use the Replace statement to insert new rows in a table and/or replace existing rows in a table.
The REPLACE() function replaces all occurrences of a substring within a string, with a new substring.
SELECT REPLACE(REPLACE(REPLACE(REPLACE('3*[4+5]/{6-8}', '[', '('), ']', ')'), '{', '('), '}', ')'); We can see that the REPLACE function is nested and it is called multiple times to replace the corresponding string as per the defined positional values within the SQL REPLACE function.
SET Col1 = Col2, Col2 = Col1; When you run above update statement, the values of the columns will be swapped in SQL Server. There is no need for temporary column, variable or storage location in SQL Server.
You have a number of choices:
TRUE
, FALSE
Boolean value.Use (as pointed in this answer)
SELECT CASE WHEN hide = 0 THEN FALSE ELSE TRUE END FROM
Or if Boolean is not supported:
SELECT CASE WHEN hide = 0 THEN 'false' ELSE 'true' END FROM
I got the solution
SELECT CASE status WHEN 'VS' THEN 'validated by subsidiary' WHEN 'NA' THEN 'not acceptable' WHEN 'D' THEN 'delisted' ELSE 'validated' END AS STATUS FROM SUPP_STATUS
This is using the CASE This is another to manipulate the selected value for more that two options.
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