How do I select a 1 as a bit in a sql-server view?
You can use the CONVERT operator.
SELECT id, name, CONVERT(bit, 1) AS activeFROM users
CAST or CONVERT will work.
select id, name, CAST(1 AS bit) as activefrom users
1
is the display for a true bit. What are your trying to achieve.
Doing
select CAST('true' AS bit) as active
returns 1
also.
Yes, you cast it to bit:
select id, name, cast(1 as bit) as activefrom users
This can also be useful to improve performance when comparing to a bit value in some situations:
select id, namefrom userswhere active = cast(1 as bit)
(In this example it might make no practical difference, but I have seen an actual difference in more complicated queries.)