title: How to import csv data into sql using powershell import-csv
body: <p>I have used similar code from one of the questions and used that to import the csv data to sql table but having a weird error. unable to locate it in my editor and needed an additional pair of eyes.</p>
  <pre><code>$database = 'ABC_Test'
  $server = 'ABCTEST.com'
  $table = 'XYZ\A12.ABC_PayCode'
  Import-CSV C:\Users\Downloads\sampledata.csv | ForEach-Object {Invoke-Sqlcmd `
  -Database $database -ServerInstance $server `
  -Query &quot;insert into $table VALUES ('$($_.EMPLOYEE_ID)','$($_.FIRST_NAME)','$($_.LAST_NAME)','$($_.WORK_DATE)','$($_.EARNINGS_CODE)','$($_.HOURS)')&quot;
  }
  </code></pre>
  <p>Throws me an error into
  Invoke-Sqlcmd : Incorrect syntax near ''.
  At \mgroupnet.com\RedirectedFolders\Documents\powershell.ps1:5 char:69</p>
  <ul>
  <li>... Users\qd90\Downloads\sampledata.csv | ForEach-Object {Invoke-Sqlcmd `</li>
  <li>
  <pre><code>                                                      ~~~~~~~~~~~~~~~
  </code></pre>
  <ul>
  <li>CategoryInfo          : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException</li>
  <li>FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand</li>
  </ul>
  </li>
  </ul>