I have 2 while loops, one inside the other, that iterate over 2 different datasets and I want the outer while loop's first row data to loop through all the rows in the inner while loop looking for a match and if not, move onto the second row in the outer loop, again looping through all the records in the inner while loop. However, after the first outer loop's record has looped through all the records in the inner loop, the second row in the outer loop does not loop through the records in the inner loop; it's as if the first attempt at going through all the records in the inner loop did not reset itself back to the beginning! Here is my code - can someone tell me where I am going wrong?
$PgConnString = "select pgName from table1"
$MsConnString = "SELECT msName FROM table2";
$PgDbConn = CreateDbConnection "Postgres";
$PgDbCmd = CreateDbCommand $PgConnString $PgDbConn;
$PgReaderOutput = $PgDbCmd.ExecuteReader();
$MsDbConn = CreateDbConnection "MSSql";
$MsDbCmd = CreateDbCommand $MsConnString $MsDbConn;
$MsReaderOutput = $MsDbCmd.ExecuteReader();
while ($PgReaderOutput.Read())
{
$ReporterName = $PgReaderOutput.GetValue(0);
Write-Output "Current Reporter is: $ReporterName";
while ($MsReaderOutput.Read())
{
$CurrMsRec = $MsReaderOutput.GetValue(0);
Write-Output "Current SQL record is: $CurrMsRec";
if($CurrMsRec -eq $ReporterName)
{
$Match = 1
Write-Output "Matched"
}
else
{
Write-Output "No Matched"
$Match = 0;
}
}
If($Match -eq 1)
{
Write-Output "The reporter: $ReporterName has not been sent an email; send them one!";
}
}