Project-Neith icon indicating copy to clipboard operation
Project-Neith copied to clipboard

Parameterized Queries?

Open theabraxas opened this issue 6 years ago • 3 comments

Getting some errors like the following when imported data as variables include single quotes or similar characters:

Invoke-Sqlcmd : Incorrect syntax near 'Neil'.
Unclosed quotation mark after the character string ')
'. 
 Msg 102, Level 15, State 1, Procedure , Line 2.
At line:15 char:9
+         Invoke-Sqlcmd -Query $Query
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException
    + FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand

I've heard Invoke-Sqlcmd2 might have a solution to this, this might be a better way forward

theabraxas avatar Feb 04 '19 05:02 theabraxas

I believe I have an old example of using parameterized queries with this cmdlet. Please remind me this week unless you figure it out before.

gallman avatar Feb 04 '19 06:02 gallman

Sweet, thanks!

On Sun, Feb 3, 2019 at 10:05 PM gallman [email protected] wrote:

I believe I have an old example of using parameterized queries with this cmdlet. Please remind me this week unless you figure it out before.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/theabraxas/UltimateDashboard/issues/14#issuecomment-460140313, or mute the thread https://github.com/notifications/unsubscribe-auth/AF3MvAvsIlEZrWwBoBWcsWMbWm5HoFWDks5vJ825gaJpZM4agjmo .

theabraxas avatar Feb 04 '19 06:02 theabraxas

I haven’t checked the latest version of the SqlServer module but the dbaTools module supports parameterized queries via their Invoke-DbaSqlQuery function.

gallman avatar Feb 04 '19 15:02 gallman