mithrandyr / SimplySql

PowerShell module for querying various SQL databases
MIT License
197 stars 31 forks source link

stop "WARNING: Query returned no resultset. This occurs when the query has no select statement or invokes a stored procedure that does not return a resultset. Use 'Invok e-SqlUpdate' to avoid this warning." #142

Closed tomerikko closed 5 months ago

tomerikko commented 5 months ago

Hey team, I have a script where i run a query against a DB to check per each ID to check if data returns. if it does the script do calculation and push it to another table, if it does not, the script move to the next ID. this is +- how I run it: Invoke-SqlQuery -Query "SELECT * From <Table_name> WHERE <id condition>"

When data do not return (and on this specific one it mostly won't) the CMD is filled with warnings. "WARNING: Query returned no resultset. This occurs when the query has no select statement or invokes a stored procedure that does not return a resultset. Use 'Invok e-SqlUpdate' to avoid this warning." I tried altering the command to use Invoke-SqlUpdate to avoid that warning, but this one will not return results for a select query. (which maked sense based on its name).

So I wonder, what are my options to avoid this warning to stop polluting my CMD? is there a flag or anything to set to say that empty Select is OK and you don't need to alert on? or perhaps a different CMD I should use?

mithrandyr commented 5 months ago

@tomerikko -- you can use the -WarningAction parameter to handle this. For instance -WarningAction Ignore will prevent these warnings from being generated.

FYI, all the cmdlets make use (or should be making use of) the Common Parameters.

tomerikko commented 5 months ago

huh, i could swear i tried that with SilighntlyContinue and it kept throwing those warnings on screen. but you are correct again, my cmd is clean again.

MANY THANKS FOR EVERYTHING YOU ARE DOING!!!!!!!!!!!!!!!!!!!!!