0

Table structure

id  col1   col2
 1  data1  false
 2  data2  true

I tried

select id, case col2 when true then col1 from table

and it is showing an internal server error. I want to select the col1 from table when the corresponding col2 is true.

jarlh
  • 42,561
  • 8
  • 45
  • 63
  • Do you understand that when col2 is false you will still get col1 in output but it's value will be NULL? – Harsh Nov 25 '15 at 06:37

2 Answers2

2

probably just a simple syntax error in your case statment. try this..

select 
id,
case when col2=1 then col1 else 'some other value' end as computedCaseCol
from table1

see: SQL fiddle

Mortalus
  • 10,574
  • 11
  • 67
  • 117
0

Do you mean that ?

select id,col1 from tabe where col2 = 'true'

or

select id,col1 from tabe where col2 is true

??

Greg
  • 343
  • 3
  • 17
  • Thanks for the reply Greg. But i need to select some other columns and only this column (eg: col1 ) in this way. proper eg: select col3,col4,col5, (case col2 when true then col1) from table where id=1; – Jaison Abraham Nov 25 '15 at 07:26