3

PowerShell 5.1
SQL Server 2016 SP1 and SP3

If I run an identical select top 1 query between 2 SQL Server 2016 databases (one is on sp3, other is sp1) they return different types, why?

$res = Invoke-Sqlcmd -Query "select top 1 * from customer" -ServerInstance "(localdb)\MSSQLLocalDB" -Database "Database1" -OutputAs DataTables
$res.GetType()
$res

One database returns a DataTable and other returns DataRow

enter image description here

Rod
  • 14,529
  • 31
  • 118
  • 230
  • 1
    Tbh, if it really returns 2 different types in 2 different versions of the module it might be an actual bug. However since this is proprietary code from MS it's hard to tell you if this was intended or not. – Santiago Squarzon Jun 11 '22 at 01:25
  • 3
    It might be worth adding the Module versions on sp1 and sp3 and clarifying on which version the return type is the expected one. – Santiago Squarzon Jun 11 '22 at 02:15
  • If you copy/paste the commands via e.g. email, watch out for [em dashes](https://stackoverflow.com/q/67175721/1701026) – iRon Jun 11 '22 at 06:26
  • 4
    What you show is the expected (`datatable`) results, can add/show the unexpected (`datarow`) results? – iRon Jun 11 '22 at 09:42
  • Does this happen on different computers? Or maybe different Windows accounts on the same computer? What's the output of `Get-Command -Name Invoke-Sqlcmd` in both places? – AlwaysLearning Jun 12 '22 at 11:17

0 Answers0