Closed Pxtl closed 4 hours ago
Hi @pxtl, thanks for reporting the issue.
I looked into it and I have a fix for the issue you reported that I hope to push out in the upcoming v22.3.
I've also observed that there's a bit of inconsistencies today when it comes to Multiple Result Sets when one of the result set is empty (namely: what should be emitted? no data? an empty table/dataset? Or perhaps just skipping the empty sets?) that would be nice to address in the next major update (v23). Personally, I'd be inclined in making the result uniform and go with:
Of course, that can only be done in v23.x, because it would be quite a bit breaking change. What do you think?
For v22.3, I'll just try to minimize the chances of breaking changes, which should be enough to unblock you.
Using
invoke-sqlcmd
in SqlServer 22.2.0, under powershell 5.1, execute the following:This yields no results. With
-verbose
enabled we see onlyshowing how the output terminates after the first query.
Note that if the empty-result query is later in the script, this behavior does not happen.
Now, in the above example, we don't see queries two and four because they have different columns and Powershell's pipeline will base its column choice on the first result, however, we still see the VERBOSE logs from after query three.
And we can work-around Powershell's bad behavior with varying column names by using the
-outputAs DataTables
mode:So here everything works! Hooray! But only if the
where 0=1
falls later in the script. If it's a first-query we still get the old bad behavior: