473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
2 1550
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: govince | last post by:
Not sure this is realyy realted to access, but a least to asp scripting. This is what I am trying achieve, I'll try to make it as clear as possible: I am integrating a search page form a...
1
by: J | last post by:
Situation - Using the table pubs.titleauthor in a strongly typed dataset, attached to a datagrid, using the datagrid I would like to set the royaltyper field = null (the database allows nulls in...
1
by: Stu | last post by:
Hi, I am trying to return the data key field value from a dataset when I select a row in a datagrid after the datagrid has been bound to a dataset. When I an the Edit, Update and Cancel row I...
3
by: Marc Castrechini | last post by:
I have a page that changes an <ASP:Checkbox value based on a user entered value in a textboxm using client side Javascript. After my submit is fired the value for the chkMyCB.checked does not get...
0
by: Luqman | last post by:
I want to save my own Customer ID No. while saving new record in DetailView, how can I ? My DetailView is connected to ObjectDataSource which is using a Data Set. Best Regards, Luqman
5
by: Rex | last post by:
Hi, I want to change a value in one table depending on the value(s) in another table. I am trying to achieve this in a form. to elaborate I have a many-to-many relationship between tables...
6
by: cj | last post by:
If I'm sitting on a datarow for a customer and want to change his phone number only if it's blank what would I write? if myDr("phone")= "" then myDr("phone") = "mphone" endif...
1
by: cbayr249 | last post by:
I'm currently making a database for a research project and I keep running into a problem. I have one master form with the tab control and several subforms. Each subform is backed by a table that are...
5
by: parry2k | last post by:
I have one view with 3 fields like the view name is myview and it has following sql statement. select fn,ln,city from tablea I created a function like below:- create function myfun(in t...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.