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

  • mstjean - Thursday, January 4, 2018 4:33 PM

    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.

    Thank you very much for posting back - it really helps everyone out, especially those who come across your post when searching on similar issues.

    Sue