Home Forums Programming Powershell PS script works in ISE but fails in SQL JOB step with a syntax error RE: PS script works in ISE but fails in SQL JOB step with a syntax error

  • Resolved; replaced problem row with this:    "'" + $Row.$Prop + "'" 

    Also needed to modify these rows:
    $Insert = $InsertValues -join '), ('
    $InsertQuery = "INSERT INTO $DestTable ( $( $Properties -join ', ' ) ) VALUES ( $Insert )"
    Invoke-Sqlcmd -ServerInstance $DestServer -Database $DestDatabase -Query $InsertQuery

    To this:
    $Insert = $InsertValues -join '), ('
    $Cols = $Properties -join ', '
    $InsertQuery = "INSERT INTO $DestTable ( $Cols ) VALUES ( $Insert )"
    Invoke-Sqlcmd -ServerInstance $DestServer -Database $DestDatabase -Query $InsertQuery

    This code runs correctly in the ISE & in the SQL JOB.


    Cursors are useful if you don't know SQL