Skip to content

Add note about NULL handling in BIT_COUNT function - #10352

Closed
Steve Jones (way0utwest) wants to merge 2 commits into
MicrosoftDocs:livefrom
way0utwest:patch-67
Closed

Add note about NULL handling in BIT_COUNT function#10352
Steve Jones (way0utwest) wants to merge 2 commits into
MicrosoftDocs:livefrom
way0utwest:patch-67

Conversation

@way0utwest

Copy link
Copy Markdown
Contributor

Clarified behavior of BIT_COUNT with NULL values.

Clarified behavior of BIT_COUNT with NULL values.
@prmerger-automator

Copy link
Copy Markdown
Contributor

Steve Jones (@way0utwest) : Thanks for your contribution! The author(s) and reviewer(s) have been notified to review your proposed change.

1 similar comment
@prmerger-automator

Copy link
Copy Markdown
Contributor

Steve Jones (@way0utwest) : Thanks for your contribution! The author(s) and reviewer(s) have been notified to review your proposed change.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit aa8de06:

✅ Validation status: passed

File Status Preview URL Details
docs/t-sql/functions/bit-count-transact-sql.md ✅Succeeded

For more details, please refer to the build report.

@v-regandowner

Copy link
Copy Markdown
Contributor

Derek Wilson (@thesqlsith)

Can you review the proposed changes?

IMPORTANT: When the changes are ready for publication, adding a #sign-off comment is the best way to signal that the PR is ready for the review team to merge.

#label:"aq-pr-triaged"
@MicrosoftDocs/public-repo-pr-review-team

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Clarifies the documented behavior of BIT_COUNT when the input expression is NULL, ensuring readers understand the function’s null-propagation behavior.

Changes:

  • Added a note stating that BIT_COUNT returns NULL when passed a NULL expression.

Comment thread docs/t-sql/functions/bit-count-transact-sql.md Outdated
@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit 93195ff:

✅ Validation status: passed

File Status Preview URL Details
docs/t-sql/functions/bit-count-transact-sql.md ✅Succeeded

For more details, please refer to the build report.


For example, `SELECT BIT_COUNT (CAST (-1 AS SMALLINT))` and `SELECT BIT_COUNT (CAST (-1 AS INT))` return `16` and `32` respectively. This is intended, as the binary representation of `-1` can have a different number of bits set to `1` depending on the data type.

If *expression_value* is `NULL`, `BIT_COUNT` returns `NULL`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest something like:

If expression_value is NULL of a supported data type, BIT_COUNT returns NULL. An untyped NULL literal isn't a valid argument; cast it to a supported type.
For example:

SELECT BIT_COUNT(CAST(NULL AS int));   -- Returns NULL

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Derek. I'll pull this into an internal PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants