I have a query like this in my PowerShell Script
try{ $Query = "SELECT ID / 0 FROM Tables1" Invoke-Sqlcmd -Query $Query -ServerInstance $Global:Server -Database $Global:Database}catch {"error when running sql $Query " $error= $_}
The problem I'm having is when I run this query in Azure Data Studio then I get an error and that look fine but
SELECT ID / 0 FROM Table1Msg 8134, Level 16, State 1, Line 1Divide by zero error encountered.
when I run the query inside my trycatch block ins my PowerShell script then some reason it's not outputting the error even though I wrap it inside trycatch block.
So I'm just wondering how could I catch the sql statement errors in my PowerShell Script?