0

I have two tables each originating from seperate SQL-queries. The first one E has 7 columns and the second S has 3. The first column is the identifier. I want to include the values from S into E so that I can run an alogrithm for each row and export all values in one csv.

With now 2600 rows the matching takes ~4-5 minutes. Is there a more efficient way to do this? I want to be able to run the script very regularly and for more than 10,000 entries.

foreach($row in $E){
    $ID = $row.ID
    $mS = $S | ?{ $_.ID -match ("^"+$ID+"$")}
    $value1 = $mS.value1
    $value2 = $mS.value2
    $row.value1 = $value1
    $row.value2 = $value2
}
Akarik
  • 1
  • 1
  • add some example rows for both tables... – Avshalom Nov 08 '22 at 09:01
  • Use a hashtable see also [In Powershell, what's the best way to join two tables into one?](https://stackoverflow.com/a/45483110/1701026). Using this [`Join-Object script`](https://www.powershellgallery.com/packages/Join)/[`Join-Object Module`](https://www.powershellgallery.com/packages/JoinModule): `$E |Join $S -On ID` – iRon Nov 08 '22 at 09:17
  • Great links. For a more basic solution: https://stackoverflow.com/a/74305843/7571258 – zett42 Nov 08 '22 at 09:18

0 Answers0