View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jamie Collins Jamie Collins is offline
external usenet poster
 
Posts: 593
Default Duplicate Record....

sal21 wrote ...

if you have another way to controll duplicate during the
import is welcome


The usual way to identify duplicates between two tables is to create
an OUTER JOIN on a key and test for null key values in the other
table.

I've seen a few of your posts now and the details seem to change each
time so I've made the following assumptions:

- the connection is to you database
- the database table is named TOTALE
- the Excel workbook is saved as C:\MyWorkbook.xls
- the Excel worksheet is named L0785_TOTALE
- the column headers are in row 6 and the data starts on the next
row
- I've ignored column X because it has no column header and the
cells contain formulas
- the columns in the database and worksheet are the same
- the key is SERVIZIO.

The following selects rows present in the database but missing from
the worksheet:

SELECT
T1.[DATA CONT#], T1.DIP, T1.COD, T1.[C/C],
T1.NOMINATIVO, T1.[CAUS#], T1.[IMP# DARE],
T1.[IMP# AVERE], T1.[VAL#], T1.[SPORT# MITT#],
T1.[ANOM#], T1.[DESCRIZIONE OPERAZIONE],
T1.[INDICE (C#R#O#)], T1.ABI, T1.CAB,
T1.[PAG#/IMP#], T1.[NR# ASS#], T1.MT, T1.SERVIZIO,
T1.[NOTE B#O#U#], T1.SPESE, T1.[DATA ATTIVITA'],
T1.COD1
FROM TOTALE AS T1
LEFT JOIN
[Excel 8.0;HDR=YES;Database=C:\MyWorkbook.xls;].[L0785_TOTALE$A6:W65535]
AS T2 ON T1.SERVIZIO = T2.SERVIZIO
WHERE T2.SERVIZIO IS NULL
;

A couple of further points:

Your column names are not very database friendly: look at how they
appear in the above query. Consider renaming them using just
alphanumeric and underscore characters i.e. no spaces, periods,
slashes, etc.

Attempting to change your Excel data using SQL (UPDATE or INSERT INTO)
will cause problems because some of your columns are hidden.

Jamie.

--