473,499 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

MERGE syntax error

The statement:

merge into nullid.animals_et_in t1 using is3.animals t2
on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and
t1.sire_regnum=t2.regnum
when matched then update set t1.sire_bhid=t2.bhid
when not matched then update set t1.sire_bhid=0
go

gets the error message:

Error: An unexpected token "when not matched then" was found following
"T1.SIRE_BHID=T2.BHID". Expected tokens may include: "<merge_when_spec1>".

which I don't understand. I read the syntax diagrams and explanations
and thought that would be valid syntax. Any explanation or reference
would greatly appreciated. DB2 UDB V8.1.5 under Linux.
Nov 12 '05 #1
4 5298
In article <9q***************@fe05.lga>, Bob Stearns (rstearns1241
@charter.net) says...
The statement:

merge into nullid.animals_et_in t1 using is3.animals t2
on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and
t1.sire_regnum=t2.regnum
when matched then update set t1.sire_bhid=t2.bhid
when not matched then update set t1.sire_bhid=0
go

gets the error message:

Error: An unexpected token "when not matched then" was found following
"T1.SIRE_BHID=T2.BHID". Expected tokens may include: "<merge_when_spec1>".

which I don't understand. I read the syntax diagrams and explanations
and thought that would be valid syntax. Any explanation or reference
would greatly appreciated. DB2 UDB V8.1.5 under Linux.


You are not allowed to do an insert:

NOT MATCHED
Indicates the operation to be performed on the rows where the ON
search condition is false or unknown. Only INSERT or signal-statement
can be specified after THEN.
Nov 12 '05 #2
Gert van der Kooij wrote:
In article <9q***************@fe05.lga>, Bob Stearns (rstearns1241
@charter.net) says...
The statement:

merge into nullid.animals_et_in t1 using is3.animals t2
on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and
t1.sire_regnum=t2.regnum
when matched then update set t1.sire_bhid=t2.bhid
when not matched then update set t1.sire_bhid=0
go

gets the error message:

Error: An unexpected token "when not matched then" was found following
"T1.SIRE_BHID=T2.BHID". Expected tokens may include: "<merge_when_spec1>".

which I don't understand. I read the syntax diagrams and explanations
and thought that would be valid syntax. Any explanation or reference
would greatly appreciated. DB2 UDB V8.1.5 under Linux.

You are not allowed to do an insert:

NOT MATCHED
Indicates the operation to be performed on the rows where the ON
search condition is false or unknown. Only INSERT or signal-statement
can be specified after THEN.

... which when one thinks about it is the only option... How could DB2
update a row that it didn't find to begin with?

Cheers
Serge
Nov 12 '05 #3
Serge Rielau wrote:
Gert van der Kooij wrote:
In article <9q***************@fe05.lga>, Bob Stearns (rstearns1241
@charter.net) says...
The statement:

merge into nullid.animals_et_in t1 using is3.animals t2
on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and
t1.sire_regnum=t2.regnum
when matched then update set t1.sire_bhid=t2.bhid
when not matched then update set t1.sire_bhid=0
go

gets the error message:

Error: An unexpected token "when not matched then" was found
following "T1.SIRE_BHID=T2.BHID". Expected tokens may include:
"<merge_when_spec1>".

which I don't understand. I read the syntax diagrams and explanations
and thought that would be valid syntax. Any explanation or reference
would greatly appreciated. DB2 UDB V8.1.5 under Linux.

You are not allowed to do an insert:

NOT MATCHED
Indicates the operation to be performed on the rows where the ON
search condition is false or unknown. Only INSERT or signal-statement
can be specified after THEN.


.. which when one thinks about it is the only option... How could DB2
update a row that it didn't find to begin with?

Cheers
Serge

Doh!! I continue to think of 'not matched' meaning t1 not matched. It is
of course t2 which is not matched. Syntax like 'into not matched' and
'using not matched' (these choices are abominable, but it's late) would
be useful and cover all 3 cases.
Nov 12 '05 #4
Bob Stearns wrote:
Serge Rielau wrote:
Gert van der Kooij wrote:
In article <9q***************@fe05.lga>, Bob Stearns (rstearns1241
@charter.net) says...

The statement:

merge into nullid.animals_et_in t1 using is3.animals t2
on t1.sire_assoc=t2.assoc and t1.sire_prefix=t2.prefix and
t1.sire_regnum=t2.regnum
when matched then update set t1.sire_bhid=t2.bhid
when not matched then update set t1.sire_bhid=0
go

gets the error message:

Error: An unexpected token "when not matched then" was found
following "T1.SIRE_BHID=T2.BHID". Expected tokens may include:
"<merge_when_spec1>".

which I don't understand. I read the syntax diagrams and
explanations and thought that would be valid syntax. Any
explanation or reference would greatly appreciated. DB2 UDB V8.1.5
under Linux.

You are not allowed to do an insert:

NOT MATCHED
Indicates the operation to be performed on the rows where the ON
search condition is false or unknown. Only INSERT or signal-statement
can be specified after THEN.

.. which when one thinks about it is the only option... How could DB2
update a row that it didn't find to begin with?

Cheers
Serge


Doh!! I continue to think of 'not matched' meaning t1 not matched. It is
of course t2 which is not matched. Syntax like 'into not matched' and
'using not matched' (these choices are abominable, but it's late) would
be useful and cover all 3 cases.

DB2 has an (obvious) extension to the standard allowing you to add
predicates to MATCHED and NOT MATCHED. So you can indeed have more than
one UPDATE, DELETE and/or INSERT clause.
The ON-clause partitiones teh set into MATHCED and NOT MATCHED the
predicates sub-partitioned into the various phases.

Not sure if that covers what you're asking for.
Cheers
Serge
Nov 12 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4812
by: Karthik | last post by:
Hi, We have setup a publisher and a distributor in SQL 2000 running SP3. Alongwith this we have setup a merge replication agent and its running successfully inside the same network. I allow...
8
9490
by: Squirrel | last post by:
Hi everyone, I've created a mail merge Word doc. (using Office XP) , the data source is an Access query. Functionality I'm attempting to set up is: User sets a boolean field to true for...
3
5566
by: Andy Davis | last post by:
I have set up a mail merge document in Word 2003 which gets its data from my Access 2000 database. I want to set up a button on a form that: 1. runs the query to provide the dat for the merge...
3
3512
by: Bob Stearns | last post by:
We have a very poorly performing MERGE statement (an hour or more on tables of ~10000 and ~100000). This may require building temporary tables with appropriate indexes, but I thought I would ask...
4
18612
by: marklawford | last post by:
Hi guys, I'm getting the following error message when trying to run a MERGE statement I'm putting together. The syntax looks right to me But i must be missing something. The "srce" table...
0
890
by: mayankaerry | last post by:
Hi, I am facing an error on calling Datset update method. Following is my scenario: There are Three Excel Files Test1.xls,Test2.xls and Test3.xls. There is data in Test1.xls as under: B
6
8970
by: amitabh.mehra | last post by:
I want to trap errors (RI errors), if any, that might turn up during merge in DB2. Is there some feature like the one in Oracle: MERGE INTO... WHEN MATCHED THEN UPDATE... WHEN NOT MATCHED THEN...
1
6525
by: Esther Lane | last post by:
Hello! First off, many many thanks to Albert who wrote the Mail Merge code for MS Access I am using. It has been working beautifully for a few years. However, my client just (without notice!)...
3
2392
by: subramanian100in | last post by:
Consider the following program: #include <cstdlib> #include <iostream> #include <set> #include <map> #include <algorithm> #include <iterator> #include <utility>
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.