MERGE executing both WHEN MATCHED and WHEN NOT MATCHED

Database

MERGE executing both WHEN MATCHED and WHEN NOT MATCHED

Hi all:

I'm facing problems using MERGE in V2R6 Teradata Database. The client app is VB using ADO throught OLEDB.

The fact is that I've traced the errors and it turns out that the MERGE is executing BOTH WHEN MATCHED and WHEN NOT MATCHED clauses, and it bombs out with 'Duplicate unique prime key error'.

The code is something like:

"MERGE INTO MY_DB.MY_TABLE d " & _
"USING VALUES ( ?, ?, ?) o(par1, par2, par3) " & _
"ON d.ID = o.par1 " & _
"WHEN MATCHED THEN UPDATE " & _
"SET COL2 = o.par2, " & _
" COL3 = o.par3, " & _
"WHEN NOT MATCHED THEN INSERT " & _
"(ID, COL2, COL3) VALUES (o.par1, o.par2, o.par3)"

When I comment the 'WHEN NOT MATCHED' part I see that the update has been properly done (for values that already exist in the DB). But when I un-comment this part, the error 'Duplicate unique prime key error in MY_DB.MY_TABLE' appears (again, for values that already exist in the DB). Thus, it is updating AND inserting for a given set of values (????)

Has anybody experienced something like this? Is this a TD bug? Am I doing something wrong? Am I overlooking something?

Any clues will be appeciated.

Thanks in advance.

Cheers.

Carlos.