The following query shows me a
error Conversion failed when converting the varchar value 'IF EXISTS' to data type bit.
I don't know how to solve it, column4 is of type BIT but sometimes I want to obtain the type bit and sometimes I want to obtain a text so that it has more meaning for the user, I control that with a variable called @TextoOrBit.
Thank you very much in advance for your support and if you can guide me on how to obtain the desired result.
DECLARE
@TextoOrBit BIT
SET @TextoOrBit = 0;
SELECT
COLUMNA1,
COLUMNA2,
COLUMNA3,
CASE @TextoOrBit
WHEN 1 THEN
CASE COLUMNA4 WHEN 1 THEN 'SI EXISTE' ELSE 'NO EXISTE' END
ELSE
CASE COLUMNA4 WHEN 1 THEN CAST(1 AS BIT) ELSE CAST(1 AS BIT) END
END AS COLUMNA4_custom
FROM
TABLA_DATOS
If you define a class for the
List<>
, you can execute the query only once and have propertiesfrom the query you get the value
bit
of the field that of course in c# is a bool, but then for the text you only expose a propertyreadonly
that allows you to obtain the text that you will show to the user and everything is encapsulated in the class