Downvoting is for the benefit of the wider audience. This query cannot be run by multiple users simultaneously. Using an actual temporary table (with a name prefixed with a
#
) would fix that issue but then you would be unable to access that table outside the dynamic query's scope. — Andriy M 43 secs ago