0

DB で毎日行わなければならないレポートの生成を自動化しようとしていますが、スケジュール タスクを作成できるように、まずジェネレーターがそれに応じて自己動作する必要があります。

そこで、DB からデータを取得して CSV にエクスポートするスクリプトを作成しましたが、問題は、最初の SQL で追加されず、エクスポートが停止することです。

$serverName = $Global:setupConfiguration["GENERAL SETTINGS"]["ODBC_DATASOURCE_NAME"]
$databaseName = $Global:setupConfiguration["CASINO CONFIGURATION"]["DATABASENAME"]
$recordSetToFileName = @{0='1.csv';}
$currentRecordSetIndex = -1
$progAccount = $null
$iniBaseSection = $false
#Execute the SQL on the local database and dumps a csv in C:/Automation/

#fetches the data to temp table
$sqlFile = "$($Global:globalVariables.executionPath)\sql\0.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv $fileName -notypeinformation -force -Encoding utf8

#selects from temp table and exports.

$sqlFile = "$($Global:globalVariables.executionPath)\sql\1.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv  $fileName -notypeinformation  -Encoding utf8 -Force


$sqlFile = "$($Global:globalVariables.executionPath)\sql\2.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv -Append -Path $fileName -notypeinformation  -Encoding utf8 -Force

$sqlFile = "$($Global:globalVariables.executionPath)\sql\3.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv  -Append -Path $fileName -notypeinformation  -Encoding utf8 -Force

$sqlFile = "$($Global:globalVariables.executionPath)\sql\4.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv -Append -Path $fileName -notypeinformation  -Encoding utf8 -Force

$sqlFile = "$($Global:globalVariables.executionPath)\sql\5.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv -Append -Path $fileName -notypeinformation -Encoding utf8 -Force

$sqlFile = "$($Global:globalVariables.executionPath)\sql\6.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv -Append -Path $fileName -notypeinformation -Encoding utf8 -Force

$sqlFile = "$($Global:globalVariables.executionPath)\sql\7.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv -Append -Path $fileName -notypeinformation -Encoding utf8 -Force

$sqlFile = "$($Global:globalVariables.executionPath)\sql\8.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv -Append -Path $fileName -notypeinformation -Encoding utf8 -Force

$sqlFile = "$($Global:globalVariables.executionPath)\sql\9.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv -Append -Path $fileName -notypeinformation -Encoding utf8 -Force

$sqlFile = "$($Global:globalVariables.executionPath)\sql\10.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv -Append -Path $fileName -notypeinformation -Encoding utf8 -Force

$sqlFile = "$($Global:globalVariables.executionPath)\sql\11.sql"
$data = Invoke-SqlQuery -File $sqlFile -Server $serverName -Database $databaseName
$fileName = "$($Global:globalVariables.localDirectory)\$($recordSetToFileName[0])"
$data | export-csv -Append -Path $fileName -notypeinformation -Encoding utf8 -Force
4

1 に答える 1