Calculate Age in SQL Server by counting completed birthdays, not calendar years. This post compares DATEDIFF, a DATEADD correction and a compact integer version on a bike club table, handles February 29 birthdays and ends with a reusable function for age on any date.
NULLIF Denominators: Keep Zero and Missing Values Visible
NULLIF denominators turn zero into NULL for a deliberate division policy. This complete example keeps zero, missing inputs and integer truncation visible beside the decimal result.
REVERSE: Keep Trailing Spaces in String Reversal
REVERSE changes character order while keeping supplied spaces. Use visible boundaries and byte counts to distinguish empty and missing inputs.
COLLATIONPROPERTY CodePage: Identify Text Encoding
COLLATIONPROPERTY CodePage reports varchar encoding metadata. Compare code pages 1252 and 65001 without confusing inspection with text conversion.
DATEPART Quarter: Keep the Year Beside the Quarter
DATEPART quarter identifies a calendar component. I keep its year when reporting separate periods. A cross-year January case shows how quarter-only grouping combines events.
Weighted Average: Keep Group Totals and Value Counts
A weighted average preserves each group’s contribution. I compare unequal groups before combining their means. Group totals and populated-value counts reconstruct the underlying average without treating missing readings as zero.
SQL SERVER – Introduction to SERVERPROPERTY and example
SERVERPROPERTY is a handy system function that returns server values like collation, edition and instance name. My script lists every property in one result.







