T-SQL bugs, pitfalls, and best practices – pivoting and unpivoting
SEPTEMBER 12, 2019
This article is the fifth part in a series about T-SQL bugs, pitfalls and best practices. Here I'll describe the trap, the potential bug, and a best practice that prevents the bug. Perhaps you intuitively expected the shipperid column to be the grouping column because it appears in the SELECT list, but as you can see in the plan, in practice you got a much longer list of columns, including orderid, which is the primary key column in the source table.