how to merge to CSV files as a scheduled task

We have two CSV files exported from two different apps   on a weekly basis. We have to merge them and want to run it  as schedule task.
if i do it in SQL it will look like
Select a.key1, a.first, a. last, a.key2, b.number into c where a.key2=b.key2 and  a source1, b source2, c results

How can it be done with excel so we run it a a scheduled task? I all looking for a working syntax.
Who is Participating?
Eric WoodfordConnect With a Mentor Software Systems Specialist 3Commented:
You should be able to code something like this in powershell then trigger the script as a scheduled task.

For example, I coded this a while back to do something similar:
abbas abdullaCommented:

you can use this code
1. Change the paths to match your paths.
2.  Copy the code into new Notepad file
3.  Save the notepad file with  .bat extension.
4. schedule a task to open this file at the time or event you want the CSV files to be merged.

:: Merge CSV
@echo off
set Source=C:\Users\Myuser\Downloads\Undo
set Dest=C:\Users\Myuser\Downloads\Undo\allbat.csv
::for /f "delims=" %%a in ('dir "%Source%\*.csv" /b /s') do (
::copy "%%a" "%Dest%"
copy "%Source%\*.csv" /b %Dest%


Open in new window

leop1212Author Commented:
when you merge two files i don' t see how you align lines by a.key2=b.key2 ?
Eric WoodfordSoftware Systems Specialist 3Commented:
If you are referring to my script, I use cmd line parameters..
 [parameter(Mandatory=$true,HelpMessage="Path and filename for source CSV 1")][ValidateScript({Test-Path $_ })][string]$csv1Name,
    [parameter(Mandatory=$true,HelpMessage="Propery from CSV1 to join files on.")][string]$csv1Property,
    [parameter(Mandatory=$true,HelpMessage="Path and filename for source CSV 2")][ValidateScript({Test-Path $_ })][string]$Csv2Name,
    [parameter(Mandatory=$true,HelpMessage="Propery from CSV2 to join files on.")][string]$csv2Property,
    [parameter(Mandatory=$true,HelpMessage="Path and Name for combined CSV file")][string]$JoinedCSV

Open in new window

$CSV1Property and $CSV2Property are the names of the keys $a.key and $b.key

In your sample CSV files, you have duplicate fields with different results. When I designed the script, I didn't have duplicate and different results (i.e. first name = first name in both CSV)

 .\CSVJoin.ps1 -csv1Name .\source1.csv -Csv2Name .\source2.csv -csv1Property key2 -csv2Property key2 -JoinedCSV .\myResults.csv

Open in new window

source files combine to make results.csv
Zeth LarssonCommented:
Do the source files have same name, and location every week?
What shall happend with old source files after merge to result?
Shall it be any role for the name of the latest result file?
Is all fields always in the same order as in your sample?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.