How do I select a 1 as a bit in a sql-server view?

I want to create a view in which I select something like the following:

select id, name, 1 as active
from users

However, I want the active field, which I am creating in the select statement (it doesn't exist in the table), to be a bit field. Is there a way to do this?


Solution 1:

You can use the CONVERT operator.

SELECT id, name, CONVERT(bit, 1) AS active
FROM users

CAST or CONVERT will work.

Solution 2:

select id, name, CAST(1 AS bit) as active
from 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.