I’m trying to import data from csv files into one table which consolidates the data and counts occurances of failing some tests.
Nearly all the work is done, except for the fact that now i can import the same data multiple times and it simply appends it to the bottom of my table.
SQL code so far:
strSQL = "INSERT INTO [Tested] ([Date], [Batch], [Item], [Test1NOK], [Test2NOK], [Approved], [Total]) " & _
"SELECT [Date], [Batch], [Item], " & _
"SUM(IIF (Test1 = " & Chr(34) & "NOK" & Chr(34) & ",1,0)) AS Test1NOK, " & _
"SUM(IIF (Test2 = " & Chr(34) & "NOK" & Chr(34) & ",1,0)) AS Test2NOK, " & _
"SUM(IIF (Test2 = " & Chr(34) & "OK" & Chr(34) & ",1,0)) AS Approved, " & _
"COUNT(*) AS [Total] " & _
"FROM [TempImport] " & _
"GROUP BY [Date], [Batch], [Item]"
db.Execute strSQL
I read somewhere that you can possibly use a LEFT JOIN to check if the same data is already present and only append new values, but i have no idea how to add that statement into the above statement.
Any help is greatly appreciated.