473,545 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to capture rows affected via merge command?

I've got a batch etl process in which I typically wrap DML with selects
in order to capture the number of rows affected. For example:
SELECT 'rows updated', COUNT(*)
FROM NEW TABLE
( UPDATE stage_asset
SET ip_int = ip_to_bigint(ip _string)
WHERE ip_int IS NULL )

How can I do this for a merge? For example:

MERGE INTO asset_component comp
USING stage_asset stag
ON comp.asset_id = stag.core_asset _id
AND comp.asset_comp onent_type = 'os'
WHEN MATCHED THEN
UPDATE SET
comp.os_name = stag.core_os_na me ,

comp.os_id = stag.core_os_id
,
comp.asset_comp onent_name = stag.core_os_na me
WHEN NOT MATCHED THEN
INSERT (asset_id,
asset_component _type,
asset_component _name,
os_name,
os_id )
VALUES (stag.core_asse t_id,
'os',
stag.core_os_na me,
stag.core_os_id )

Thanks in advance!

Ken

Sep 4 '06 #1
4 7043
kenfar wrote:
I've got a batch etl process in which I typically wrap DML with selects
in order to capture the number of rows affected. For example:
SELECT 'rows updated', COUNT(*)
FROM NEW TABLE
( UPDATE stage_asset
SET ip_int = ip_to_bigint(ip _string)
WHERE ip_int IS NULL )

How can I do this for a merge? For example:

MERGE INTO asset_component comp
USING stage_asset stag
ON comp.asset_id = stag.core_asset _id
AND comp.asset_comp onent_type = 'os'
WHEN MATCHED THEN
UPDATE SET
comp.os_name = stag.core_os_na me ,

comp.os_id = stag.core_os_id
,
comp.asset_comp onent_name = stag.core_os_na me
WHEN NOT MATCHED THEN
INSERT (asset_id,
asset_component _type,
asset_component _name,
os_name,
os_id )
VALUES (stag.core_asse t_id,
'os',
stag.core_os_na me,
stag.core_os_id )
Unfortunately no can do.
FWIW, SELECT FROM MERGE is on my personal wish-list too.

Cheers
Serge


--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 4 '06 #2
Serge Rielau wrote:
kenfar wrote:
>I've got a batch etl process in which I typically wrap DML with selects
in order to capture the number of rows affected. For example:
SELECT 'rows updated', COUNT(*)
FROM NEW TABLE
( UPDATE stage_asset
SET ip_int = ip_to_bigint(ip _string)
WHERE ip_int IS NULL )

How can I do this for a merge? For example:

MERGE INTO asset_component comp
USING stage_asset stag
ON comp.asset_id = stag.core_asset _id
AND comp.asset_comp onent_type = 'os'
WHEN MATCHED THEN
UPDATE SET
comp.os_name = stag.core_os_na me ,

comp.os_id = stag.core_os_id
,
comp.asset_comp onent_name = stag.core_os_na me
WHEN NOT MATCHED THEN
INSERT (asset_id,
asset_component _type,
asset_component _name,
os_name,
os_id )
VALUES (stag.core_asse t_id,
'os',
stag.core_os_na me,
stag.core_os_id )
Unfortunately no can do.
FWIW, SELECT FROM MERGE is on my personal wish-list too.
BTW, you are aware that you can retrieve the rows affected from the
SQLCA.ERRD[3] or in SQL PL: GET DIAGNOSTICS rcnt = ROW_COUNT

And that, of course, works also with MERGE
Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 4 '06 #3
Serge Rielau wrote:
BTW, you are aware that you can retrieve the rows affected from the
SQLCA.ERRD[3] or in SQL PL: GET DIAGNOSTICS rcnt = ROW_COUNT

And that, of course, works also with MERGE
Thanks Serge. I'm piloting this process within a bash shell, and so
calling it like this:
sql="SELECT 'rows updated: ', COUNT(*) \
FROM NEW TABLE \
( UPDATE core.stage_asse t \
SET core_org_id = $org_id \
WHERE LOWER(account) = '$account' ) "
db2 -x "$sql"
rc=$?
if [ "$rc" != "0" ]; then
abort $rc
fi

Is there a way to get to the SQLCA from bash (or any shell
interpreter)?

Thanks again,

Ken

Sep 4 '06 #4
kenfar wrote:
Serge Rielau wrote:
>BTW, you are aware that you can retrieve the rows affected from the
SQLCA.ERRD[3] or in SQL PL: GET DIAGNOSTICS rcnt = ROW_COUNT

And that, of course, works also with MERGE

Thanks Serge. I'm piloting this process within a bash shell, and so
calling it like this:
sql="SELECT 'rows updated: ', COUNT(*) \
FROM NEW TABLE \
( UPDATE core.stage_asse t \
SET core_org_id = $org_id \
WHERE LOWER(account) = '$account' ) "
db2 -x "$sql"
rc=$?
if [ "$rc" != "0" ]; then
abort $rc
fi

Is there a way to get to the SQLCA from bash (or any shell
interpreter)?
Try the -a option.

--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 4 '06 #5

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

Similar topics

5
5075
by: Chris Stromberger | last post by:
When issuing updates in mysql (in the console window), mysql will tell you if any rows matched and how many rows were updated (see below). I know how to get number of rows udpated using MySQLdb, but is there any way to get the number of rows matched? I want to find out, when rows updated = 0, if there were no updates because the row wasn't...
3
2766
by: Tome73 | last post by:
How can I easily add the rows of DataTable1 to the rows of DataTable2. Both queries are from the same table. I can always use the column names with myRow, but I was wishing for a shortcut. When I try this it doesn’t work. for (int i = 0; i < dataTable1.Rows.Count; i++) { myRow = dataTable2.NewRow(); myRow = dataTable1.Rows;...
7
12041
by: Egor Shipovalov | last post by:
I'm implementing paging through search results using cursors. Is there a better way to know total number of rows under a cursor than running a separate COUNT(*) query? I think PostgreSQL is bound to know this number after the first FETCH, isn't it? On a side note, why queries using LIMIT are SO terribly slow, compared to cursors and...
0
1486
by: Mark Barinstein | last post by:
Hello. W2K, db2 v7, FP10a. Before now our replication worked properly. But some days ago capture suddenly stopped loggin and filling cd tables without any messages. The last message was like this: -- 2004-03-03-09:17:36 ASN0105I: Data that has been copied was pruned from the change data table ASN.IBMSNAP_UOW at SEQ = ...
12
1984
by: Graham Blandford | last post by:
Hi all, Would someone be able to tell me the most 'graceful' way of removing unwanted rows from a dataset based on a condition prior to update? OR, resetting the rows all to unchanged after they are initally added to the recordset. I create a dataset, which begins empty after the initial .Fill. Then I create several rows with some...
2
2098
by: muntyanu | last post by:
Hi all, I have problem when merging existing DataTable into new dataset. DataSet ds = new DataSet(); while ( done ) { // fill myCustomDataSet.MyTable with data ds.Merge( myCustomDataSet.MyTable, bPreserveChanges, MissingSchemaAction.Add ); ds.AcceptChanges(); // tried with and without this line
11
2533
by: UDBDBA | last post by:
Hi: This is a merge questions which has been posted and answered... in my case need more clairification when target table (tableB) matched multiple rows to be updated based on the ON condition for a single row from source table (tableA). There is a one to many relationship from source to target table (because of the ON condition). We also...
2
4556
by: Rich | last post by:
Hello, Is there a way to capture the Records Affected count when performing a table Update on a Sql Server table using a DataAdapter? How is this done? Thanks, Rich
3
15951
by: Carl K | last post by:
using MySQLdb, I do cursor.execute("update...") How can I tell how many rows were affected ? Carl K
0
7411
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7669
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7926
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7439
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4962
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3468
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1901
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1028
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.