If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > QUERY Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-08-04, 14:40
udbraja udbraja is offline
Registered User
 
Join Date: Sep 2004
Posts: 111
Angry QUERY Help

Team

Here is the three tables created succssfully
================================

db2 "create table emp (eid int not null primary key,salary int)"
DB20000I The SQL command completed successfully.


db2 "create table mgr (eid int not null primary key,bonus int)"
DB20000I The SQL command completed successfully.


db2 "create table src (eid int not null primary key,salary int,bonus int,ismgr char (1))"
DB20000I The SQL command completed successfully.

1st query is success
=================

db2 "with i1 as (select eid, bonus, ismgr from new table (insert into emp include (bonus int, ismgr char(1)) select eid, salary,bonus,ismgr from src)) select count(*) from new table (insert into mgr select eid,bonus from i1 where ismgr='Y')"

1
-----------
0

1 record(s) selected.

2nd Query failed <--- Please help
=============
db2 "with i1 as (select eid, salary, bonus from new table (merge into emp include (bonus int, ismgr char(1)) using src on (1=0) when not matched and ismgr='N' then insert (eid,salary) values(src.eid,src.salary) when not matched nd ismgr='Y' then set eid=src.eid,salary=src.salary,bonus=src.bonus,ismg r=src.ismgr)select
count(*) from new table (insert into mgr select eid,salary,bonus from i1 where ismgr='Y')"

SQL0104N An unexpected token "with i1 as (select eid, sala" was found
following "BEGIN-OF-STATEMENT". Expected tokens may include:
"<labeled_begin_atomic>". SQLSTATE=42601

Thanks
Ra
Reply With Quote
  #2 (permalink)  
Old 12-08-04, 14:53
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
What are you trying to do with the second query?

Andy
Reply With Quote
  #3 (permalink)  
Old 12-09-04, 09:24
udbraja udbraja is offline
Registered User
 
Join Date: Sep 2004
Posts: 111
To accomplish merge statement/output

Thanks
Raj
Reply With Quote
  #4 (permalink)  
Old 12-09-04, 15:51
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
The MERGE statement is for modifying data only. You cannot use it in a select--just like you cannot use INSERT, UPDATE, or DELETE.

Andy
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On