Please check my Insert Query (avoid inserting duplicates) (1 Viewer)

MsLady

Traumatized by Access
Local time
Yesterday, 20:15
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)));"
 

MsLady

Traumatized by Access
Local time
Yesterday, 20:15
Joined
Jun 14, 2004
Messages
438
 

KeithG

AWF VIP
Local time
Yesterday, 20:15
Joined
Mar 23, 2006
Messages
2,592
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.
 

MsLady

Traumatized by Access
Local time
Yesterday, 20:15
Joined
Jun 14, 2004
Messages
438
Okay, i'll try. Thanks Keith
 

Users who are viewing this thread

Top Bottom