hierarchyid GetLevel identifies depth within a logical path. The read-only example distinguishes the root, children, grandchildren and a fractional sibling label.
SQL SERVER – Get Numeric Value From Alpha Numeric String – Get Numbers Only
Reader Christofer improved my logic to get a numeric value from alpha numeric string data. His stored procedure uses REVERSE and PATINDEX.
Percent of Total With SUM() OVER() in One Query
Calculate percent of total with SUM() OVER(), group and running shares, safe numeric division, and checks for zero totals.
REPLACE With COLLATE: Choose Case Matching Explicitly
REPLACE with COLLATE controls which substrings match. Preview case-dependent results before applying a text replacement policy.
FOR JSON PATH: Choose Whether NULL Properties Appear
FOR JSON PATH omits NULL properties by default. Compare INCLUDE_NULL_VALUES with missing properties and empty strings in a complete output example.
SQL SERVER – Function to Retrieve First Word of Sentence – String Operation
A friend asked for a UDF that returns only the first word of a sentence. Here is my script with CHARINDEX and SUBSTRING, and how to turn it into a function.
CROSS APPLY Aggregate: An Empty Input Can Still Return a Row
CROSS APPLY aggregate behavior depends on whether the right-side query actually produces a row. I inspect that query before assuming unmatched customers disappear. An aggregate without GROUP BY can return a row even when its input is empty.







