How can I update multiple rows based on comparison of fields table1 and 2
I create the following SQL to test what I thought was a method to update those records where the fields below match, but what ends up happening is that the update functions works the first time, and then basically updates everything to null. I am not understanding what I am doing wrong. New at this.
UPDATE SLS_HDR B
SET ( B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT )
= (SELECT
A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE
FROM
SLS_HDR_TEMP A
WHERE
A.FIN_COMP = B.FIN_COMP AND
A.LOG_COMP = B.LOG_COMP AND
A.ORD_NO = B.ORD_NO AND
A.TRANS_DT = B.TRANS_DT AND
A.BP_TYPE = B.BP_TYPE AND
A.STATUS <> B.STATUS);
Can anyone advise?
Thank you,
Edited by: 903292 on Dec 19, 2011 1:15 PM
you donot have where clause in your update so un-matched rows will be updated with null values
UPDATE SLS_HDR B
SET ( B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT )
= (
SELECT
A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE
FROM
SLS_HDR_TEMP A
WHERE
A.FIN_COMP = B.FIN_COMP AND
A.LOG_COMP = B.LOG_COMP AND
A.ORD_NO = B.ORD_NO AND
A.TRANS_DT = B.TRANS_DT AND
A.BP_TYPE = B.BP_TYPE AND
A.STATUS= B.STATUS
WHERE EXISTS
select null from SLS_HDR_TEMP A
WHERE
A.FIN_COMP = B.FIN_COMP AND
A.LOG_COMP = B.LOG_COMP AND
A.ORD_NO = B.ORD_NO AND
A.TRANS_DT = B.TRANS_DT AND
A.BP_TYPE = B.BP_TYPE AND
A.STATUS= B.STATUS
)OR using Merge
Merge into SLS_HDR B
using SLS_HDR_TEMP A
on (A.FIN_COMP = B.FIN_COMP AND
A.LOG_COMP = B.LOG_COMP AND
A.ORD_NO = B.ORD_NO AND
A.TRANS_DT = B.TRANS_DT AND
A.BP_TYPE = B.BP_TYPE AND
A.STATUS= B.STATUS)
when matched then update set (B.ORD_DT, B.SHIP_ADD_CD, B.INV_ADD_CD, B.LOB, B.STATUS,
B.ORD_TYPE, B.HDR_ROUTE, B.PRICE_LIST, B.CUST_ORDER, B.REF_A, B.REF_B,
B.ORD_REF, B.ORD_DISC, B.SREP, B.SREP2, B.PLAN_DEL_DT, B.TXTA, B.TXTB,
B.INV_CONTACT, B.SHIP_CONTACT, B.SOLD_CONTACT, B.PAY_CONTACT, B.ORD_AMT,B.UPDATED_DT ) = (A.ORD_DT, A.SHIP_ADD_CD, A.INV_ADD_CD, A.LOB, A.STATUS,
A.ORD_TYPE, A.HDR_ROUTE, A.PRICE_LIST, A.CUST_ORDER, A.REF_A, A.REF_B,
A.ORD_REF, A.ORD_DISC, A.SREP, A.SREP2,A.PLAN_DEL_DT, A.TXTA, A.TXTB,
A.INV_CONTACT, A.SHIP_CONTACT, A.SOLD_CONTACT,A.PAY_CONTACT, A.ORD_AMT, SYSDATE)HTH...
Thanks
Similar Messages
-
How can I update multiple rows?
Hi all,
How can I realize an Update on multiple rows? An Update statement would look like this
UPDATE table SET value = oldvalue + x WHERE condition_field > y;My problem is: How can I execute such a statement with BC4J? I don't linke to step through the complete result set row by row.
Thanks,
AxelGet your application module object and issue this statement:
am.getTransaction().executeCommand(<string>);This should be what you're looking for. -
How can i update multiple row in a advance table
Dear all,
hope you are well enough.
suppose i have a table in a OA page where there are several transactions.
i would like to add a check box in front of every row.
when i check the transactions(rows of OA pages) and submit then one column of a table will be updated in database.
how can i implement that.
Please explain
Regards,
MofizurHi,
Refer below code for iteration:
OAViewObject appVO = (OAViewObject)am.findViewObject("ApprovalsWVO1");
OARow row = (OARow)appVO.first();
for(int i=0;i<appVO.getRowCount();i++)
String appStatus=appVO.getCurrentRow().getAttribute("ApprovalStatus").toString();
if(appStatus.equalsIgnoreCase("NEW"))
newRow.setAttribute("appTrans",Boolean.FALSE);
else
newRow.setAttribute("appTrans",Boolean.TRUE);
System.out.println(appStatus);
row = (OARow)appVO.next();
Regards
Meher Irk -
How can I update multiple rows in table using a single form button and checkboxes
I have a project where the visitors can select multiple productos and once the click on the PURCHAS button it updates the selected records.
You have not mentioned the programming language that you are using, but here's a link that could help you if you are using ASP.
http://csharpdotnetfreak.blogspot.com/2009/05/edit-multiple-records-gridview-checkbox.html
Also, have a look at this discussion thread
http://forums.asp.net/t/1470882.aspx -
Update multiple rows based on two columns in same row
I have a 1000 rows in a table I would like to update with a unique value. This unique value is a cocatenation of two columns in teh same row.
Each row has a (i) date and a (ii) time and a (iii) date_time column. I would like to update the date_time (iii) column with a cocatenation of the (i) date and (ii) time columns.
I know how I would update a single row but how can I update multiple rows with a cocatenation of each of the two columns - i.e put a different value into the date_time column for each row?this?
update table tab_name
set date_time =date||time
where your_condition -
How can I use multiple row insert or update into DB in JSP?
Hi all,
pls help for my question.
"How can I use multiple rows insert or update into DB in JSP?"
I mean I will insert or update the multiple records like grid component. All the data I enter will go into the DB.
With thanks,That isn't true. Different SQL databases have
different capabilities and use different syntax, That's true - every database has its own quirks and extensions. No disagreement there. But they all follow ANSI SQL for CRUD operations. Since the OP said they wanted to do INSERTs and UPDATEs in batches, I assumed that ANSI SQL was sufficient.
I'd argue that it's best to use ANSI SQL as much as possible, especially if you want your JDBC code to be portable between databases.
and there are also a lot of different ways of talking to
SQL databases that are possible in JSP, from using
plain old java.sql.* in scriptlets to using the
jstlsql taglib. I've done maintenance on both, and
they are as different as night and day.Right, because you don't maintain JSP and Java classes the same way. No news there. Both java.sql and JSTL sql taglib are both based on SQL and JDBC. Same difference, except that one uses tags and the other doesn't. Both are Java JDBC code in the end.
Well, sure. As long as you only want to update rows
with the same value in column 2. I had the impression
he wanted to update a whole table. If he only meant
update all rows with the same value in a given column
with the same value, that's trivial. All updates do
that. But as far as I know there's know way to update
more than one row where the values are different.I used this as an example to demonstrate that it's possible to UPDATE more than one row at a time. If I have 1,000 rows, and each one is a separate UPDATE statement that's unique from all the others, I guess I'd have to write 1,000 UPDATE statements. It's possible to have them all either succeed or fail as a single unit of work. I'm pointing out transaction, because they weren't coming up in the discussion.
Unless you're using MySQL, for instance. I only have
experience with MySQL and M$ SQL Server, so I don't
know what PostgreSQL, Oracle, Sybase, DB2 and all the
rest are capable of, but I know for sure that MySQL
can insert multiple rows while SQL Server can't (or at
least I've never seen the syntax for doing it if it
does).Right, but this syntax seems to be specific to MySQL The moment you use it, you're locked into MySQL. There are other ways to accomplish the same thing with ANSI SQL.
Don't assume that all SQL databases are the same.
They're not, and it can really screw you up badly if
you assume you can deploy a project you've developed
with one database in an environment where you have to
use a different one. Even different versions of the
same database can have huge differences. I recommend
you get a copy of the O'Reilly book, SQL in a
Nutshell. It covers the most common DBMSes and does a
good job of pointing out the differences.Yes, I understand that.
It's funny that you're telling me not to assume that all SQL databases are the same. You're the one who's proposing that the OP use a MySQL-specific extension.
I haven't looked at the MySQL docs to find out how the syntax you're suggesting works. What if one value set INSERT succeeds and the next one fails? Does MySQL roll back the successful INSERT? Is the unit of work under the JDBC driver's control with autoCommit?
The OP is free to follow your suggestion. I'm pointing out that there are transactions for units of work and ANSI SQL ways to accomplish the same thing. -
How can i use multiple row subquery in update statement
Hai All
I using group function in my update statement.. and i need to update more rows so i need to use multiple row
subquery pls tell me how to use multiple row subquery in update statement
For example
while i am using this like this i got an error
update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
Pls tell me how to use with example
Thanks & regards
Srikkanth.MHai Man
Thanks for ur response Let me clear what i need
First step Fetch the records as text file and stores into table T1
and the next step is i have seperated the text using substring and stores in different columns of a table
There are two shifts 0815 to 1645 and 1200 and 2000
Here I rep IN and O rep OUT
Empno date time inout
001 01-01-10 0815 I
002 01-01-10 0815 I
003 01-01-10 0818 I
001 01-01-10 1100 0
001 01-01-10 1130 I
002 01-01-10 1145 0
002 01-01-10 1215 I
004 01-01-10 1200 I
005 01-01-10 1215 I
004 01-01-10 1315 O
004 01-01-10 1345 I
001 01-01-10 1645 0
002 01-01-10 1715 0
003 01-01-10 1718 0
004 01-01-10 2010 0
005 01-01-10 2015 0
This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
T2 contains like this
Empno Intime Intrin Introut Outtime Date
001 0815 1100 1130 1645 01-01-10
002 0815 1145 1215 1715 01-01-10
003 0818 1718 01-01-10
004 1200 1315 1345 2010 01-01-10
005 1215 2015 01-01-10
This what i am trying to do man but i have little bit problems Pls give some solution with good example
And my coding is
declare
emp_code varchar2(25);
in_time varchar2(25);
out_time varchar2(25);
Cursor P1 is
Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
From temp_att
group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
ORDER BY enpno,pdate,ptime;
begin
for r2 in p1 loop
declare
bar_code varchar2(25);
begin
select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
if r2.inout ='O' then
update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
end if;
end loop;
exception
when no_data_found then
if r2.inout ='I' then
insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
end if;
end;
end loop;
commit;
end;
Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
and how can i use it in the update statement
Thanks In Advance
Srikkanth.M -
I have many bookmarks that I like to have readily available on the toolbar. With the older versions of Firefox, I was able to have multiple rows of icons that I grouped by topic. I have now wasted a lot of time trying to find a way to have multiple rows in version 4.0. I do not want to use the down arrow on the right.
This can be done by adding a userstyle with the Stylish add-on.
# First install the Stylish add-on - https://addons.mozilla.org/en-US/firefox/addon/stylish
# Go to http://userstyles.org/styles/29428 and click on "Install with Stylish"
# Restart Firefox and you should then have a multi-row bookmarks toolbar. -
10GR2 - How can I load multiple row values into one field?
Hi
Can anyone please help with a problem I'm having with merging data.
The source table has multiple entries for the same Id e,g,
ID Code
1 123
1 234
2 123
2 567
The output should only have one row per ID e.g.
ID Code_List
1 123;234
2 123;567
Do you know what operator I could use that would allow me to do this? I've looked at unpivot but I think I would need multiple output fields (one for each Code). I have to concatinate the codes and separate with a semi-colon.
Thanks
GBQ) Input data
=============
COL_0,COL_4
1235,"G0123,G124,G25,G6"
1236,"G01,G23,G124,G25,G6"
1237,"G0123,G1,G24,G25,G6"
1238,"G,G0123,G124,G25,G6"
1239,"G0123124,G256"
Output
======
TEST_ID,TEST_VAL
1235,G0123
1235,G124
1235,G25
1235,G6
1236,G01
1236,G23
1236,G124
1236,G25
1236,G6
1237,G0123
1237,G1
1237,G24
1237,G25
1237,G6
1238,G
1238,G0123
1238,G124
1238,G25
1238,G6
1239,G0123124
1239,G256
I wrote this procedure...
declare
rcd_cnt number;
test_id123 number;
junk_1 number;
cd_occurences number;
child_count number;
str_abc varchar2(200);
char_pos number default 0;
cd_temp_str varchar2(50);--:= 'G0123,G124,G25,G6';
begin
select nvl(count(col_4),0) into rcd_cnt from test_ee where col_4 is not null;
for aa in 1 .. rcd_cnt loop
select col_0,rownum rn,nvl(trim(col_4),0) into test_id123,junk_1,cd_temp_str from (select col_0,rownum rn,col_4 from test_ee where col_4 is not null) where rn = aa;
--dbms_output.put_line('...I am in for loop...' || cd_temp_str);
--dbms_output.put_line('===================' || rcd_cnt || '.................' ||aa);
cd_occurences := length(cd_temp_str) - length(replace(cd_temp_str,','));
dbms_output.put_line(cd_temp_str || '...Str Occurences are ...'||cd_occurences ||'**************'||test_id123);
child_count :=0;
for z in 1..length(cd_temp_str)+1 loop
child_count := child_count+1;
if(instr(cd_temp_str,',') > 0) then
char_pos := instr(cd_temp_str,',',1,1);
str_abc := substr(cd_temp_str,1,char_pos-1);
dbms_output.put_line('..Partial String of..'|| z ||'..is.....' || str_abc);
insert into test_xx(test_id,test_val) values(test_id123,str_abc);
end if;
cd_temp_str := substr(cd_temp_str,char_pos+1,length(cd_temp_str));
if(cd_occurences=child_count) then
dbms_output.put_line('..Partial String of..is.....' || cd_temp_str);
insert into test_xx(test_id,test_val) values(test_id123,cd_temp_str);
end if;
end loop; -- close for of z */
--dbms_output.put_line('...I am in end for loop...');
end loop; -- close for of aa
end;
instead of procedure,is there any way from sqlqery. -
How can I update multiple IOS devices from one computer without downloading IOS each time
My company is on a VERY slow internet connection, and at the moment we are using a cellular modem to increase our bandwidth. This connection is a metered connection. The 1 Gb download for IOS 7 will kill all of my purchased bandwidth, and has a potential to both take a while and/or cost a fortune. I need a way to update 58 iPhone 4's, 4S's and 5's to IOS 7 while only downloading IOS for each device type once. We are using iTunes to do this update as the update utility on the phone has caused 3 of our units to crash and lose all their data. 2 of which were bricked and had to be replaced by applecare. We had a utility for that when I worked for apple a few years ago that used iTunes in this manner, but I am not sure this exists on the consumer side. Does anyone know where i can look for this solution?
- Since you have iOS 4.x, the only way to update the iPod is to connect the iPod to a computer and update via iTunes. See:
iOS 4: Updating your device to iOS 5 or later
- If you following these instructions you can update the iPod without losing anything. WHen you restore from backup as the article says the iPod will also be updated.
Syncing to a "New" Computer or replacing a "crashed" Hard Drive: Apple Support Communities -
How can i update multiple records at same time in psa
Hi,
i need to modify certain column's value in psa. for one of InfoObject fix value i need to change to some other value, can i write some routine or any other way to do so quickly.
thnxIf you are in prod, its tough to write code to manipulate PSAs. First of all, you need to transport your Program. Also, if you make a mistake, you can potentially change other PSAs.
If you insist, get the name of the PSA. Go to RSA1, PSA tab. THere, right click on your infosource and select Delete PSA. DON'T DELETE anything in this screen. Just copy the Table name (look around, you will find it there). Now, go to SE16 and lok at the table contennts. If you give Req, data pack, etc, you can access multiple records. Now, write the program "carefully" to access and change records in this table.
There is another way, but this will work-out for you.
Uday-Ram Chamarthy -
How can we select multiple rows in table control for module pool program?
hi guru's
i cannt able to select multiple table control rows for deletion of records please give any code to select rows?
regrards,
satheesh.On the Table Control attributes there is a "Selectability" option where you choose one of: None, Single, or Multiple. In your code you then need to pick up which rows have the selection column set to 'X'.
-
Update multiple rows involving spatial data
Hi,
i have 2 table, that are
temp
store_id
store_state
geom mdsys.sdo_geometry
us_states
state
geom mdsys.sdo_geometry
i have indexed both table with spatial index.
If i wanna find state that temp.geom is inside us_states.geom using
SQL> select state from us_states, temp
where sdo_inside(temp.geom, us_states.geom) = 'TRUE';
it's work
but if i wanna update temp.store_state using
SQL> update temp set store_state = (select state from us_states
where sdo_inside(temp.geom, us_states.geom) = 'TRUE');
it gives this error
update temp set store_state = (select state from us_states where sdo_inside(temp.geom, us_states.geom) = 'TRUE')
ERROR at line 1:
ORA-13226: interface not supported without a spatial index
ORA-06512: at "MDSYS.MD", line 1723
ORA-06512: at "MDSYS.MDERR", line 8
ORA-06512: at "MDSYS.SDO_3GL", line 62
ORA-06512: at "MDSYS.SDO_3GL", line 192
any idea how can i update multiple rows that involving spatial data?
Thanks
HadiHadi,
There are a number of things wrong with the second item. First up you most likely will return more than one row, which is not allowed as the = expects only one item.
Here is what I would use, which will update everything that meets the requirements, and ignore the rest:
UPDATE (
SELECT /*+ bypass_ujvc */
state, store_id, store_state
FROM temp, us_states
WHERE sdo_inside(temp.geom, us_states.geom) = 'TRUE')
SET store_state = state;
With the /*+ bypass_ujvc */ you're telling the db to not worry about requiring a "unique join view condition" -- which roughly mean "trust me, my rows are key preserved." This is important since there is really no "hard" key-based relationship to tie the two together.
However, unless you really think there are stores that border on two states, this will run much quicker with an anyinteract comparison.
Bryan -
Updating multiple rows in a table in ADF
Hi
How do we update multiple rows in a table.
Onclicking a update button the changed rows must be updated.Hi Prince,
currently I am selecting one row from the table and rendering a region at the top of the table and capturing the user entered data with the following code:
ViewObjectVOImpl vo = getViewObjectVO1();
Row CurrentRow = vo.getCurrentRow();
//After this I perform the checks like user entered value is not null or check input as per business logic.
if(CurrentRow.getAttribute("attributeName") ==null){
//Add what message you want to display
//Add other business logic.
After making all the checks, i commit it.
getOADBTransaction().commit();
Now in my new page I am capturing the user input in the table itself like an excel sheet. Suppose there are ten rows in my advanced table on my page, and each row has one editable field. I have one save button at the bottom of the table.
Now on clicking the save button I have to capture the user input, check whether there is any null value and if all the entered data is correct then only I should commit it.
Can you please let me know how we can accomplish that.
Regards
Hawker -
BC4J datagrid to update multiple rows
Hi,
How do we update multiple rows at a time in a BC4J JSP with Struts. I intend to have a datagrid control on a JSP so that users may update multiple rows at a time and click 'Update' once.
There is a possible (workaround) solution using struts nested tags but one would lose the benefits of JBO tags on using struts tags (e.g Calendar control would not be visible for Date input).
Any implementation suggestions?
Regards,
AshishDoes the database only contain data where there are events on a given 15-minute time slot?
Maybe you are looking for
-
I just completed Samsung Note 3 required software update and now the time showing on the top of my phone is incorrect. The first number of the hour is not being shown. (example: correct time is 11:33 but it shows 1:33.....another example: correct t
-
IST OPERATION SUBCONTRACTED WITH REFERENCE TO ORDER
Hello SAP Experts, i am doing operation subcontractiing. My first operation is subcontracted. So, I have assigned PP02 control key to first operation and maintained external processing data for opration in routing. When i saved the order, for that o
-
I have a Griffin express slot/34 multi-card reader. I was copying data from my FW800 drive to a microSD card via SD adapter in the griffin reader. The transfer froze up and I couldn't seem to force a successful restart of finder. I did a hard shutdow
-
I am trying to run ExportContent in silent mode as documented in this manual: http://download-west.oracle.com/docs/html/B14176_01/migrating.htm#sthref1333 However, no matter what I do, the command results in a GUI interface for ifsimportexport. My en
-
I plugged in the iphone 5 to PC via itunes what should i do between Set up as new iphone or Restore from this back up? i just want to transfer all my purchased apps and contacts to my new iphone? don't want to screw thing up. Please help..... thank