Improving SQL query readability (1)

From SQL Server 2008, using ‘TRUE’ and ‘FALSE’ is supported for BIT data type in SQL query. You can use this to improve SQL query readability.

Per doco, the string value ‘TRUE’/’FALSE’ used will be converted to BIT values automatically. (No, you can’t use ‘YES’/’NO’ or ‘YAY’/’NAY’…)

Microsoft’s official doc on BIT data type

So instead of using 0/1, you can use ‘TRUE’/’FALSE’ to improve query readability.

Examples
(IsEnrolled is of BIT data type)


SELECT [Id]
,[Age]
,[Name]
FROM [dbo].[Students]
WHERE [IsEnrolled] = 'TRUE'

UPDATE [dbo].[Students]
SET [IsEnrolled] = 'FALSE'
WHERE [Id] = 3

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s