How to convert a boolean to string in a Store procedure SQL

4

I have the following procedure (select) that gives me some information:

 SELECT id_accion, accion_tomada, CAST(fec_inicio AS VARCHAR) AS fecha_ini, 
 CAST(fec_fin AS VARCHAR) AS fecha_fin, estatus 
 FROM detalles WHERE id_downtime = @id_dt  

The status field is of bit type, it returns a 0 or a 1, I want to adjust the select for when I return a 0 = 'open' and 1 = 'closed'. Any ideas?

    
asked by Richard 02.05.2018 в 22:44
source

1 answer

2

You can use CASE like this:

SELECT id_accion, accion_tomada, CAST(fec_inicio AS VARCHAR) AS fecha_ini, 
CAST(fec_fin AS VARCHAR) AS fecha_fin, 
CASE estatus 
  WHEN 0 THEN 'abierto'
  WHEN 1 THEN 'cerrado'
END AS status
FROM detalles WHERE id_downtime = @id_dt  
    
answered by 02.05.2018 / 22:50
source