Home Dashboard Directory Help
Search

T-SQL should have a bit literal format by Greg Low - Australia


Status: 

Active


22
0
Sign in
to vote
Type: Suggestion
ID: 611171
Opened: 10/6/2010 3:38:15 PM
Access Restriction: Public
Primary Feedback Item: 356470
1
Workaround(s)
view

Description

T-SQL has literal formats for most data types. There is no literal format for a bit.

For example, if I wish to return a bit column from a CASE statement such as:

SELECT CASE WHEN something THEN 1 ELSE 0 END AS Somecolumn

I have to wrap it in a CAST or CONVERT to avoid getting an integer type.
Details
Sign in to post a comment.
Posted by Microsoft on 4/21/2011 at 6:28 PM
Hello Greg,
I have resolved your request as duplicate of below:

http://connect.microsoft.com/SQLServer/feedback/details/356470/support-syntax-for-typed-literal-values

Your specific request is covered there and what you are asking for is truth values (TRUE, FALSE) as specified by ANSI SQL. We will look at it for a future version.

--
Umachandar, SQL Programmability Team
Posted by Microsoft on 11/29/2010 at 9:09 AM
Hi Greg,

Thank you for the suggestion, it does make sense and we will put it on the list for a future release.

Thanks
- Tobias, SQL Server Engine
Posted by Microsoft on 11/29/2010 at 9:09 AM
Hi Greg,

Thank you for the suggestion, it does make sense and we will put it on the list for a future release.

Thanks
- Tobias, SQL Server Engine
Sign in to post a workaround.
Posted by RicardoPretrazey on 12/1/2011 at 4:55 AM
Hi,

I know this isn't perfect, but it makes the code easier to read...

Create two functions TRUE and FALSE which return a 'bit' value of 1 or 0 respectively.

Then you can just use dbo.TRUE() or dbo.FALSE() - which is a bit easier on the eye than the convert/cast.

CREATE FUNCTION TRUE()
RETURNS bit
AS
BEGIN
    return convert(bit,1)
END
GO

CREATE FUNCTION FALSE()
RETURNS bit
AS
BEGIN
    return convert(bit,0)
END
GO

Cheers,
Rich.