By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,237 Members | 1,234 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,237 IT Pros & Developers. It's quick & easy.

Using MERGE to change a field value when there is no match

P: n/a
I want to use MERGE to UPDATE the rows when there is a match. If there
is no match, I want to INSERT the rows, and at the same time change a
column value to a constant. For example, change the PURGE_INDICATOR to
'Y' to all inserted rows. Is there an elegant way to achieve this?

Aug 29 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
dh***********@hotmail.com wrote:
I want to use MERGE to UPDATE the rows when there is a match. If there
is no match, I want to INSERT the rows, and at the same time change a
column value to a constant. For example, change the PURGE_INDICATOR to
'Y' to all inserted rows. Is there an elegant way to achieve this?
MERGE INTO T USING S ON ...
WHEN NOT MATCHED THEN INSERT (purge, c1, c2, c3)
VALUES('Y', s.c1, s.c2, s.c3)

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Aug 29 '06 #2

P: n/a
Thanks.

Serge Rielau wrote:
dh***********@hotmail.com wrote:
I want to use MERGE to UPDATE the rows when there is a match. If there
is no match, I want to INSERT the rows, and at the same time change a
column value to a constant. For example, change the PURGE_INDICATOR to
'Y' to all inserted rows. Is there an elegant way to achieve this?
MERGE INTO T USING S ON ...
WHEN NOT MATCHED THEN INSERT (purge, c1, c2, c3)
VALUES('Y', s.c1, s.c2, s.c3)

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Aug 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.