Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parameterized Queries? #14

Open
theabraxas opened this issue Feb 4, 2019 · 3 comments
Open

Parameterized Queries? #14

theabraxas opened this issue Feb 4, 2019 · 3 comments
Labels
bug Something isn't working

Comments

@theabraxas
Copy link
Owner

theabraxas commented Feb 4, 2019

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

@gallman
Copy link
Collaborator

gallman commented Feb 4, 2019

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.

@theabraxas
Copy link
Owner Author

theabraxas commented Feb 4, 2019 via email

@gallman
Copy link
Collaborator

gallman commented Feb 4, 2019

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

@theabraxas theabraxas added this to the Version 1 Release milestone Feb 17, 2019
@theabraxas theabraxas added the bug Something isn't working label Feb 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants