# \[HELP\] Invoke-Sqlcmd

**URL:** <https://forums.powershell.org/t/help-invoke-sqlcmd/7689>\
**Category:** PowerShell Help\
**Created:** [December 9, 2016, 3:19pm UTC](https://forums.powershell.org/t/help-invoke-sqlcmd/7689 "2016-12-09T15:19:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mitzen](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/mitzen/32/559_2.png) [@mitzen](https://forums.powershell.org/u/mitzen)\
**Post date:** [December 9, 2016, 3:19pm UTC](https://forums.powershell.org/t/help-invoke-sqlcmd/7689/1 "2016-12-09T15:19:48Z")

</div>

Hey all,

I’m having an issue getting my command the way I desire.

The working command I am using is as follows: ‘SELECT [Document Type], Type, [Document No\_], No\_, Description FROM dbo.[company.here] WHERE [Document Type] = 1 AND Type = 2 AND [Document No\_] = ‘WSO-0108111’’

I need to have the command have it like this the followng but I don’t know how to get it to work with a variable:

The working command I am using is as follows: ‘SELECT [Document Type], Type, [Document No\_], No\_, Description FROM dbo.[company.here] WHERE [Document Type] = 1 AND Type = 2 AND [Document No\_] = ‘$wso’’

$wso = Whatever the user inputs.

In order for the command to properly work, it needs to be surrounded by the quotes ‘$wso’’

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [December 10, 2016, 2:49am UTC](https://forums.powershell.org/t/help-invoke-sqlcmd/7689/2 "2016-12-10T02:49:30Z")

</div>

```
"'SELECT [Document Type], Type, [Document No_], No_, Description FROM dbo.[company.here] WHERE [Document Type] = 1 AND Type = 2 AND [Document No_] = '$wso"""
```
... looks weird for me, but if it's this you want it should work actually.

BTW: Do yourself and us a favor and format your code as code here in the forum, thanks

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:39pm UTC](https://forums.powershell.org/t/help-invoke-sqlcmd/7689/3 "2024-05-16T20:39:57Z")

</div>


