Skip to content

Fix query_snapshots schema mismatch after sp_WhoIsActive upgrade#401

Merged
erikdarlingdata merged 1 commit intodevfrom
fix/query-snapshots-schema-mismatch
Mar 3, 2026
Merged

Fix query_snapshots schema mismatch after sp_WhoIsActive upgrade#401
erikdarlingdata merged 1 commit intodevfrom
fix/query-snapshots-schema-mismatch

Conversation

@erikdarlingdata
Copy link
Owner

Summary

  • sp_WhoIsActive inserts into destination tables by ordinal position, not column name
  • When sp_WhoIsActive is updated and its output column order changes (e.g., CPU moved from position 19 to 9), existing daily tables have the old layout
  • This causes Implicit conversion from data type xml to varchar is not allowed errors for the rest of the day until midnight creates a new table
  • Fix: nested TRY/CATCH on the insert — if error 257 fires, drop and recreate the daily table from the current schema, then retry

Test plan

  • sql2017 — had error before fix, passes clean after
  • sql2019 — had error before fix, passes clean after
  • sql2025 — had error before fix, passes clean after
  • sql2016 — fresh install, still works (no regression)
  • sql2022 — fresh install, still works (no regression)

🤖 Generated with Claude Code

…grade

sp_WhoIsActive inserts into destination tables by ordinal position, not
column name. When sp_WhoIsActive is updated and its output column order
changes, existing daily tables (query_snapshots_YYYYMMDD) have the old
column order, causing "Implicit conversion from data type xml to varchar"
errors until the next day when a new table is created.

Fix: wrap the insert in a nested TRY/CATCH. On error 257 (implicit
conversion), drop and recreate the daily table from the current
sp_WhoIsActive schema, then retry the insert. This makes upgrades
work immediately without waiting for midnight table rotation.

Tested on sql2017, sql2019, sql2025 — all had the error before,
all pass clean after this fix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit 11f50d4 into dev Mar 3, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant