Please check my Insert Query (avoid inserting duplicates)

MsLady

Traumatized by Access
Local time
Today, 05:05
Joined
Jun 14, 2004
Messages
438
I want to insert data into a table where a symbol does not already exist for that date. I am not sure what i am doing anymore :( So please help me verify that this won't insert duplicates? Am i using the correct logic? :confused:

Code:
"INSERT INTO StocksData (Symbol, [Security Name], [Market Category], " & _
     "[Reg SHO Threshold Flag], FileDate) " & _
     "SELECT DISTINCT Symbol, [Security Name], [Market Category], " & _
     "[Reg SHO Threshold Flag], '" & fileDate & "'" & _
     "FROM " & sTableName & _
     " WHERE ((Symbol Not In (select Symbol from StocksData)) AND (" & _
            fileDate & " Not In (select FileDate from StocksData)));"
 
bump.gif
 
Since you used the Keyword distinct it should only insert unique records. Have you tried outer joins instead of the nasty where clause (no offense). I bet the outer joins would be more efficent.
 
Okay, i'll try. Thanks Keith
 

Users who are viewing this thread

Back
Top Bottom