Forum Discussion
Chris_Ellis_777
Jun 24, 2024Copper Contributor
T-SQL Bit Field in View
Hi, I'm not sure if this is the proper place for a T-SQL question. If not, I'd appreciate a pointer to the correct forum. I have a view, and I would like a field that shows whether or not a s...
olafhelper
Jun 25, 2024Bronze Contributor
Chris_Ellis_777 force "not nullable" with the ISNULL function.
You can simply test it with
SELECT * -- Returns "int" / "not null"
FROM sys.dm_exec_describe_first_result_set
(N'SELECT CASE WHEN 1 = 1 THEN 1 ELSE 0 END AS Result', null, 0);
SELECT * -- Returns "bit" / "null"
FROM sys.dm_exec_describe_first_result_set
(N'SELECT CONVERT(bit, CASE WHEN 1 = 1 THEN 1 ELSE 0 END) AS Result', null, 0) ;
SELECT * -- Returns "bit" / "not null"
FROM sys.dm_exec_describe_first_result_set
(N'SELECT ISNULL(CONVERT(bit, CASE WHEN 1 = 1 THEN 1 ELSE 0 END), 0) AS Result', null, 0) ;