Update query with non-equijoin
I have three tables - sales_order, item and price.
I want to update item.actual_price with price.list_price.
The item table is joined to the sales_order table using order_id. The appropriate list_price for each order_id is where sales_order.order_date is between price.start_date and price.end_date for the appropriate product_id. The item table is joined to the price table using product_id.
Here is the update I have come up with, but it's giving me the wrong results.
update item i1 set i1.actual_price =
(select p.list_price from price p, item i2, sales_order s
where i1.order_id=i2.order_id
and i1.item_id=i2.item_id
and i2.product_id = p.product_id
and i2.order_id=s.order_id
and s.order_date between p.start_date and nvl(p.end_date,sysdate))
Any suggestions most welcome!
Thanks for the hint, maybe I have implemented it incorrectly, but I have done the following query and some of the actual_price figures (based on manually checking them) are incorrect. Does anything look wrong with the following:
update pcombo pi set pi.actual_price=
(select pr.list_price from price pr where pr.product_id=pi.product_id and pi.order_date between pr.start_date and nvl(pr.end_date,sysdate))
where exists
(select pr.list_price from price pr where pr.product_id=pi.product_id and pi.order_date between pr.start_date and nvl(pr.end_date,sysdate))
Similar Messages
-
Update query with CL_SQL_STATEMENT class
Hi all,
I'm trying to execute an update query with ADBC classes in order to modify two parameters (n_doc and processed) from a row with the following instructions:
l_con_ref = cl_sql_connection=>get_connection( 'DB_7879' ).
l_stmt_ref = l_con_ref->create_statement( ).
CONCATENATE 'update' gv_table ' set n_doc= ? processed = ''X'' where id_ordn = ? ' INTO l_stmt SEPARATED BY space.
GET REFERENCE OF materialdocument INTO l_dref.
l_stmt_ref->set_param( l_dref ).
GET REFERENCE OF ps_zmm_mov-id_ordn INTO l_dref.
l_stmt_ref->set_param( l_dref ).
l_stmt_ref->execute_update( l_stmt ).
However, I got the error ORA-0933: SQL command not properly ended. I guess this error occurs because I am trying to update two parameters with a single query since using the following CONCATENATE instruction
CONCATENATE 'update' gv_table ' set n_doc= ? where id_ordn = ? ' INTO l_stmt SEPARATED BY space.
results ok.
Does anybody know if it is possible to modify two parameters with only one update query with ADBC classes?
Thank you in advance!Hi Suhas,
Based on Oracle, I see it conforms almost completely ISO/IEC 9075 ([Oracle and Standard SQL|http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/ap_standard_sql.htm#10293])
UPDATE seems to conform completely [UPDATE SET clause|http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_108a.htm#2087215]
So using a comma to separate columns is true for every SQL language that conforms ISO/IEC 9075
Sandra
PS: of course SAP's "Open SQL" language does not conform at all -
Update query with prompt to input percentage
Hi I'm just starting out with Access I need to do an update query with a prompt asking the user to enter a percentage this what i have done "ProdSellPrice+ProdSellPrice *[Enter a Percentage] and I've all so done this "[ProdSellPrice]+[ProdSellPrice]
*[Enter a Percentage]" but still not working.The expression to add a percentage to a value is v*(1+(p/100)) where v is the value and p is the percentage. e.g. in the debug window:
v = 52
p= 10
? v *(1+(p/100))
57.2
So the SQL statement would be:
UPDATE tblProduct
SET ProdSellPrice = ProdSellPrice * (1+([Enter a Percentage]/100));
Ken Sheridan, Stafford, England -
Execute query with non database block
How to execute query with non database block when new form instance trigger.
Hi Kame,
Execute_Query not work with non database block. To do this Make a cursor and then assign values to non database block's items programmatically, see following example,
DECLARE
BEGIN
FOR i IN (SELECT col1, col2 FROM Table) LOOP
:block.item1 := i.col1;
:block.item2 := i.col2;
NEXT_RECORD;
END LOOP;
END;
Please mark if it help you or correct
Regards,
Danish -
Problem for running Update query with Chinese
Hi all,
I am running a web application in Lotus Domino.
I have a Lotus Script Agent which need to update Oracle 8i Database with Chinese Character throught ODBC but i find that all characters become some strange characters.
I got the problem only for update query.
I have no problem for select query for getting the chinese data.
Also, I got no problem to run the update query with chinese characters in Sqlplus.
I also try to run the same update query which the ODBC connection is pointing to an MS Access Database. It works too.
So the only things i leave is the Oracle ODBC driver.
Anythings I should do for the Oracle ODBC server?
Thanks very much.Hi, I checked the registry of Oracle and
in the NLS_LANG field, the values is AMERICAN_AMERICA.UTF8. In the server side, I set the same.
It should be okay, as i can retrieve the chinese content in the Oracle. Just that when i try to run a query contain chinese, such as,
"insert into TableA values ('���')". i will got some strange character inserted in the databasae.
Could you tell me what should i do?
Thanks a lot a lot. -
Query with non partition key in partitioning table
i compare query select with non-partition key condition in table partition with 3, 4 and 6 partition.
time execution for 3 partition faster then 4 partition, time execution for 4 partition faster than 6 partition.
i know processing query select is selection all partition, but i don't know what make time execution different between 3, 4 and 6 partition??
whether the transfer from one partition to another partition takes time?
this example sql trace query select for 3,4 and 6 partition
3 partition
SELECT *
FROM
EQU_PARAM_MONITORINGHASH WHERE TO_CHAR(time_stamp,'mm/yy')=('02/09')
call cpu elapsed disk rows
Parse 0.00 0.00 0 0
Execute 0.00 0.00 0 0
Fetch 5.70 7.57 25291 1157583
total 5.70 7.57 25291 1157583
Parsing user id: 61 (SKENARIO1)
Rows Execution Plan
0 SELECT STATEMENT MODE: ALL_ROWS
0 PARTITION HASH (ALL) PARTITION: START=1 STOP=3
0 TABLE ACCESS MODE: ANALYZED (FULL) OF
'EQU_PARAM_MONITORINGHASH' (TABLE) PARTITION: START=1 STOP=34 partition
SELECT *
FROM
EQU_PARAM_MONITORINGHASH WHERE TO_CHAR(time_stamp,'mm/yy')=('02/09')
call cpu elapsed disk rows
Parse 0.00 0.00 0 0
Execute 0.00 0.00 0 0
Fetch 5.46 8.03 25126 1157583
total 5.46 8.03 25126 1157583
Parsing user id: 62 (SKENARIO2)
Rows Execution Plan
0 SELECT STATEMENT MODE: ALL_ROWS
0 PARTITION HASH (ALL) PARTITION: START=1 STOP=4
0 TABLE ACCESS MODE: ANALYZED (FULL) OF
'EQU_PARAM_MONITORINGHASH' (TABLE) PARTITION: START=1 STOP=46 partition
SELECT *
FROM
EQU_PARAM_MONITORINGHASH WHERE TO_CHAR(time_stamp,'mm/yy')=('02/09')
call cpu elapsed disk rows
Parse 0.00 0.00 0 0
Execute 0.00 0.00 0 0
Fetch 5.73 9.13 25190 1157583
total 5.73 9.13 25190 1157583
Parsing user id: 63 (SKENARIO3)
Rows Execution Plan
0 SELECT STATEMENT MODE: ALL_ROWS
0 PARTITION HASH (ALL) PARTITION: START=1 STOP=6
0 TABLE ACCESS MODE: ANALYZED (FULL) OF
'EQU_PARAM_MONITORINGHASH' (TABLE) PARTITION: START=1 STOP=6thanks
best regards
ekoekopur wrote:
i compare query select with non-partition key condition in table partition with 3, 4 and 6 partition.
time execution for 3 partition faster then 4 partition, time execution for 4 partition faster than 6 partition.
i know processing query select is selection all partition, but i don't know what make time execution different between 3, 4 and 6 partition??
whether the transfer from one partition to another partition takes time?
this example sql trace query select for 3,4 and 6 partition
3 partition
SELECT *
FROM
EQU_PARAM_MONITORINGHASH WHERE TO_CHAR(time_stamp,'mm/yy')=('02/09')
call cpu elapsed disk rows
Parse 0.00 0.00 0 0
Execute 0.00 0.00 0 0
Fetch 5.70 7.57 25291 1157583
total 5.70 7.57 25291 1157583
Parsing user id: 61 (SKENARIO1)
Rows Execution Plan
0 SELECT STATEMENT MODE: ALL_ROWS
0 PARTITION HASH (ALL) PARTITION: START=1 STOP=3
0 TABLE ACCESS MODE: ANALYZED (FULL) OF
'EQU_PARAM_MONITORINGHASH' (TABLE) PARTITION: START=1 STOP=34 partition
SELECT *
FROM
EQU_PARAM_MONITORINGHASH WHERE TO_CHAR(time_stamp,'mm/yy')=('02/09')
call cpu elapsed disk rows
Parse 0.00 0.00 0 0
Execute 0.00 0.00 0 0
Fetch 5.46 8.03 25126 1157583
total 5.46 8.03 25126 1157583
Parsing user id: 62 (SKENARIO2)
Rows Execution Plan
0 SELECT STATEMENT MODE: ALL_ROWS
0 PARTITION HASH (ALL) PARTITION: START=1 STOP=4
0 TABLE ACCESS MODE: ANALYZED (FULL) OF
'EQU_PARAM_MONITORINGHASH' (TABLE) PARTITION: START=1 STOP=46 partition
SELECT *
FROM
EQU_PARAM_MONITORINGHASH WHERE TO_CHAR(time_stamp,'mm/yy')=('02/09')
call cpu elapsed disk rows
Parse 0.00 0.00 0 0
Execute 0.00 0.00 0 0
Fetch 5.73 9.13 25190 1157583
total 5.73 9.13 25190 1157583
Parsing user id: 63 (SKENARIO3)
Rows Execution Plan
0 SELECT STATEMENT MODE: ALL_ROWS
0 PARTITION HASH (ALL) PARTITION: START=1 STOP=6
0 TABLE ACCESS MODE: ANALYZED (FULL) OF
'EQU_PARAM_MONITORINGHASH' (TABLE) PARTITION: START=1 STOP=6
I'm assuming you recreated the table a couple of times with different numbers of hash partitions. (Tip: always use a power of two for the number of hash partitions - it keeps them all around the same size if you are using the feature on an appropriate data set.)
There isn't really enough difference in time within the database to make any sensible comment about the difference in times. I note that you have also edited out the fetch count for the 1.1 million rows fetched, and have not captured (or perhaps just not printed) the wait times, so we don't know where you spent the time inside and outside the database.
For all we can tell, the difference you are worried about might simply be network time on the fetch calls, and have nothing to do with the extract you've published.
Regards
Jonathan Lewis -
Update query with multiple foreign key parameters
I am trying to perform an update query on one field that uses multiple foreign key parameters from one table to update the other table. The data in all three foreign key parameter fields are not constant. Accuracy is absolutely critical. I tied this as well as other various scenarios with no success. Can anyone help?
Update A_table a
set a.rate = (
select b.rate
from B_table b
where b.id = a.id
and b.transdate = a.transdate
and b.orgnum = a.orgnum
and b.transdate = to_date('31/12/2007', 'dd/mm/yyyy')
)I would check symbols by a user name and number of posts before calling anyone a hot shot, especially damorgon.<br><br>
Yes version matters (due to bugs and features in each version).<br>
DDL matters because of indexes and associations.<br>
Data matters because it makes a difference on how SQL can be written.<br>
Reasons why an SQL statement don't work is because we aren't looking over your shoulder at your screen.<br><br>
damorgon did leave off his list that the best place for this question is on the PL/SQL, where they will ask you similar questions in addition to your explain plan and data volumes. -
Problem: Jstl update query with Jquery script
Hi all,
i'm writing a jsp page with this 3 star rating Jquery script to show and vote some <div> (results) .
<script type="text/javascript">
jQuery(document).ready(function($) {
$("#${Rss.pages_id}").stars({
cancelShow: false,
captionEl: $("#<%=i%>"),
callback: function(ui, type, value){
alert("Callback! ID = ${Rss.pages_id} Clicked: " + type + ", value: " + value );
$("#${Rss.pages_id}").stars("select", ${Rss.trust_value})
</script>Now i want update the value in my DB(MySql) everytime that i will click on my "star rating"..i want do this with an jstl update query.
Someone can help me?? ThanksJust so as you remember that jquery/javascript is completely client side.
JSP/JSTL is completely server side.
The only way to invoke java/JSP from javascript code is to make an http request - normally via ajax.
Given that, it doesn't make sense to put jquery code and a JSTL update query within the same JSP page.
The code to update the database should be a seperate resource called by ajax from the main page.
In that case, it doesn't have to be (and probably shouldn't be) done with JSTL. It is better done with java code within servlet/beans.
cheers,
evnafets -
Error in update query with join
hi all,
im using oracle 10g in windows.
im not able to use this update query having join......
UPDATE
b
SET
b.is_stud = 1
FROM
boy b
INNER JOIN
relationship r
ON
b.id = r.boy_id;
thanks a lot..................887268 wrote:
hi, thanks,,,,,,,,,
create table emp ( id,name,date,empno);
create table emp_status(slno,ename,empno);
i need to update "emp.name" in "emp" table from "emp_status.ename"
where emp.empno=emp_status.empno;
i.e) for all matched "empno" from both table, update "emp.name" from "emp_status.ename"Whats the relationship between emp and emp_status tables? If there exists one to one mapping for empno in both tables, then try
update emp e
set e.name = (select es.ename
from emp_status es
where e.empno = es.empno) -
Can not execute a simple update query with ms access
Hi
I am trying to execute a simple update query , this is the code I am running : I get no exeptions but the db is not being updated .
When I copy my query into access it works !
The table / columns are spelled correctly and I am able to execute select queries.
can anyone figure out what is going on
Thanks shahar
public static void main(String[] args) {
MainManager mainManager = MainManager.getInstance();
Log log = Log.getInstance();
try {
log.writeDebugMessage("befor executing query");
//stmt.executeUpdate("update trainee set Trainee_Name = 'shahar&Rafi' where Trainee_Id = 1 ");
//stmt = null ;
PreparedStatement stmt1 = con.prepareStatement("UPDATE Trainee SET Trainee_Name =? WHERE Trainee_Id =?");
String name = new String("Shahar&Rafi");
int Id = 1 ;
stmt1.setString(1,name);
stmt1.setInt(2,Id);
System.out.println(stmt1.toString());
stmt1.execute();
log.writeDebugMessage("After executing query");
catch (SQLException e ){
System.err.println("SQLException: " + e.getMessage());
}Hi All,
got the problem solved at last.
first, in the SQL string all the values must be within " ' "
for example:
INSERT INTO Trainee(Trainee_Id , Trainee_password , Trainee_Address, Trainee_Name , Trainee_Phone , Trainee_Gender , Trainee_SessionTime , Trainee_Purpose , Trainee_HealthStatus , Trainee_StartDate , Trainee_Birthday) VALUES (6,'333','hhhh','rafi',048231821,true,63,4,true, ('Feb 22, 2002'), ('Feb 22, 2002'))
second and more important,
a 'dummy' sql select query must be performed after an update query
example for code:
try{
DB.MainManager.getInstance().ExecuteUpdateQuery(A);
DB.MainManager.getInstance().getStatement().executeQuery("SELECT * FROM Trainee");
where A is the update query. -
Trying to convert SELECT query to Update query with INNER JOINS
Assalam O Alaikum!
I've tried to convert this query of mine but failed.
I wish to use it for update datasource in data GridView. I'm fetching data with it but converting it to update is not helping giving multiple errors.
I tried to share the pic but they don't let me do so. Its actually a gridView with check boxes. check the item and update it..
Here is the query. Please help me with that.
<pre>
SELECT [rightsId], [saveRights], [updateRights],
[viewRights], [deleteRights], [printRights],
[processRights], [verifyRights], [unProcessRights],
[unVerifyRights], CONVERT(VARCHAR(100),tblGroup.groupId)as groupId, convert(varchar(100),tblmenu.[menuId])as menuid
FROM [tblRights] inner join tblMenu ON
tblMenu.menuId=tblRights.menuId INNER JOIN
tblGroup ON tblGroup.groupId=tblRights.rightsId
</pre>code is fine the above query works fine with the fetching(select) but when I try to write it with update it doesn't. Here is the asp code. I'm doing nothing with c# or vb.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
DataSourceID="ratGrid" AutoGenerateColumns="False"
CssClass="GridViewStyle" Width="100%" AllowSorting="True" AutoGenerateEditButton="True" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2">
<Columns>
<asp:BoundField DataField="rightsId" HeaderText="rightsId" ItemStyle-Width="75px" SortExpression="rightsId" Visible="False">
<ItemStyle Width="75px" />
</asp:BoundField>
<asp:CheckBoxField DataField="saveRights" HeaderText="Save" SortExpression="saveRights" />
<asp:CheckBoxField DataField="updateRights" HeaderText="Update" SortExpression="updateRights" />
<asp:CheckBoxField DataField="viewRights" HeaderText="View" SortExpression="viewRights" />
<asp:CheckBoxField DataField="deleteRights" HeaderText="Delete" SortExpression="deleteRights" />
<asp:CheckBoxField DataField="printRights" HeaderText="Print" SortExpression="printRights" />
<asp:CheckBoxField DataField="processRights" HeaderText="Process" SortExpression="processRights" />
<asp:CheckBoxField DataField="verifyRights" HeaderText="Verify" SortExpression="verifyRights" />
<asp:CheckBoxField DataField="unProcessRights" HeaderText="UnProcess" SortExpression="unProcessRights" />
<asp:CheckBoxField DataField="unVerifyRights" HeaderText="UnVerify" SortExpression="unVerifyRights" />
<asp:BoundField DataField="groupId" HeaderText="groupId" ReadOnly="True" SortExpression="groupId" Visible="False" />
<asp:BoundField DataField="menuid" HeaderText="menuid" SortExpression="menuid" ReadOnly="True" Visible="False" />
</Columns>
<RowStyle CssClass="RowStyle" BackColor="#FFF7E7" ForeColor="#8C4510" />
<PagerStyle CssClass="PagerStyle" ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle CssClass="SelectedRowStyle" BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<HeaderStyle CssClass="HeaderStyle" BackColor="#A55129" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle CssClass="AltRowStyle" />
<SortedAscendingCellStyle BackColor="#FFF1D4" />
<SortedAscendingHeaderStyle BackColor="#B95C30" />
<SortedDescendingCellStyle BackColor="#F1E5CE" />
<SortedDescendingHeaderStyle BackColor="#93451F" />
</asp:GridView>
<asp:SqlDataSource ID="ratGrid"
runat="server"
ConnectionString="<%$ ConnectionStrings:Conn_Str %>"
SelectCommand="SELECT [rightsId], [saveRights], [updateRights],
[viewRights], [deleteRights], [printRights],
[processRights], [verifyRights], [unProcessRights],
[unVerifyRights], CONVERT(VARCHAR(100),tblGroup.groupId)as groupId, convert(varchar(100),tblmenu.[menuId])as menuid
FROM [tblRights] inner join tblMenu ON
tblMenu.menuId=tblRights.menuId INNER JOIN
tblGroup ON tblGroup.groupId=tblRights.rightsId"
FilterExpression="menuId like '{0}%' and [groupId] like '{1}%'" >
<FilterParameters>
<asp:ControlParameter ControlID="ddlmenu" Name="menu"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="ddlgroup" Name="Country"
PropertyName="SelectedValue" Type="String" />
</FilterParameters>
</asp:SqlDataSource>
Your table needs key(s) and you need to assign the key as DataKeys property for the GridView to make your UpDate and Delete work without coding. -
For Update Query with Wait Clause from ORACLE Forms
Hi
We are using Oracle Forms 10g running with 10g database 10.2.0.1.0. We happend to see a query which is getting generated in AWR report like Select rowid, all_columns from TableName for Update of C1 Nowait. But no such query is really written in forms and we are aware that, Any query prefixed with rowid is definitely executing from Forms. But how the ForUpdate and Nowait clause is appended to the query.
We have checked the following properties in the database Block
*1) Locking Mode is set to Automatic*
*2) Update Changed Columns only is set to YES*
*3) Query all records is set to No (Though this particular property may not be relevant to the issue)*
What is the property or setting which might trigger such a query from ORACLE Forms with ForUpdate and Nowait clause.
Any ideas/suggestions on why such behaviour. Please have a healthy discussion on this. Thanks in advance.Why have you started another thread on the same thing?
FOR UPDATE cursor is causing Blocking/ Dead Locking issues
Just use one thread to avoid confusion.
The fact that nobody has answered on the other thread for a couple of days could be to do with it being the weekend and most people are not at work.
Either be patient or, if it's more "urgent" than that, raise a SR/Tar with Oracle metalink. -
my table : workingdate
sno name startdate
1 ss 1-12-2011
2 bb 1-11-2011
I can update name or start date or both .i will pass new date,name to update through front end.
I need to validate the condition in case statement i.e. when the new date passed check whether it is greater then start date. if it is greater then it should update with new start date.
if no then it should be update it will old value.
i using below query
update workingdate set name='sss',startdate=(
case
when
(TO_DATE('2011-12-10','yyyy-MM-dd') > (select TO_DATE(startdate,'yyyy-MM-dd') from workingdate where sno=1))
then TO_DATE('2011-12-10','yyyy-MM-dd')
else
select TO_DATE(start_date,'yyyy-MM-dd') from workingdate where sno=1
end
where sno=1;
but when i execute the above query it shows me
Error report:
SQL Error: ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
how could i resolve this.......................Check this out
UPDATE workingdate
SET NAME='sss',
startdate=(CASE WHEN (TO_DATE('2011-12-10','yyyy-MM-dd') > startdate THEN TO_DATE('2011-12-10','yyyy-MM-dd') ELSE start_date END)
WHERE sno=1;Cheers
Kanchana -
UPDATE Query with logic applied
Hi Experts,
I need your help for now. Here is my requirement,
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
PL/SQL Release 11.1.0.7.0 - Production
CORE 11.1.0.7.0 Production
TNS for 32-bit Windows: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production
5 rows selected.
DROP TABLE LINE_STATUS;
DROP TABLE LINE_CHILD;
CREATE TABLE LINE_STATUS
LINE_ID INTEGER NOT NULL PRIMARY KEY,
LINE_AMT FLOAT,
LINE_FLAG INTEGER
INSERT INTO LINE_STATUS VALUES(1,1.52,0);
INSERT INTO LINE_STATUS VALUES(2,1.06,0);
INSERT INTO LINE_STATUS VALUES(3,2.05,0);
CREATE TABLE LINE_CHILD
LINECHILD_ID INTEGER NOT NULL PRIMARY KEY,
LINECHILD_LINEID INTEGER NOT NULL,
LINECHILD_AMT FLOAT
INSERT INTO LINE_CHILD VALUES (100,1,0.50);
INSERT INTO LINE_CHILD VALUES (101,1,0.50);
INSERT INTO LINE_CHILD VALUES (102,2,1.00);
INSERT INTO LINE_CHILD VALUES (103,2,0.05);NOW I NEED TO COLLECT THE SUM OF LINECHILD_AMT FOR EVERY LINECHILD_LINEID REFER LINE_STATUS(LINE_ID) AND TO CHECK
THE VALUES ARE SAME, THERE CAN BE DIFFERENCE 0.01 THEN TO UPDATE LINE_STATUS(LINE_FLAG) VALUE.
For Example:
SELECT SUM(LINECHILD_AMT) FROM LINE_CHILD WHERE LINECHILD_LINEID=1
Result is 1,
CASE
WHEN LINE_STATUS(LINE_AMT)!=SUM(LINECHILD_AMT) THEN 2
WHEN LINE_STATUS(LINE_AMT) =(LINE_STATUS(LINE_AMT)<=-0.01 OR LINE_STATUS(LINE_AMT)>=0.01 THEN 1
END CASE <<RESULT>>UPDATE LINE_STATUS,LINE_CHILD SET LINE_FLAG = CASE <<RESULT>> WHERE LINECHILD_LINEID= LINE_ID;
How can i achieve this ?
Thanks,This may not be the exact requirement as per as values of CASE statement is concern, but it should serve your purpose.
SQL> select * from LINE_STATUS;
LINE_ID LINE_AMT LINE_FLAG
1 1.52 0
2 1.06 0
3 2.05 0
SQL> SELECT * FROM LINE_CHILD;
LINECHILD_ID LINECHILD_LINEID LINECHILD_AMT
100 1 .5
101 1 .5
102 2 1
103 2 .05
SQL> ed
Wrote file afiedt.buf
1 UPDATE LINE_STATUS
2 SET LINE_FLAG=( WITH Sum_Line_Status AS ( SELECT LINE_ID S_LINE_ID,SUM(LINE_AMT) LINE_AMT_SUM
3 FROM LINE_STATUS
4 GROUP BY LINE_ID
5 )
6 ,Sum_LINE_CHILD AS ( SELECT LINECHILD_LINEID S_LINECHILD_LINEID,
7 SUM(LINECHILD_AMT) LINECHILD_AMT_SUM
8 FROM LINE_CHILD
9 GROUP BY LINECHILD_LINEID
10 )
11 SELECT
12 CASE WHEN ABS(LINE_AMT_SUM-LINECHILD_AMT_SUM)>0.01 THEN 2
13 WHEN LINE_AMT_SUM=LINECHILD_AMT_SUM THEN 1
14 WHEN ABS(LINE_AMT_SUM-LINECHILD_AMT_SUM)<=0.01 THEN 3
15 END
16 FROM Sum_Line_Status,Sum_LINE_CHILD
17 WHERE S_LINE_ID=S_LINECHILD_LINEID
18 AND S_LINE_ID=LINE_ID
19* )
20 /
3 rows updated.
SQL> SELECT * FROM LINE_STATUS;
LINE_ID LINE_AMT LINE_FLAG
1 1.52 2
2 1.06 3
3 2.05 -
Syntax errors in update query with inner joins and sub query.
Below is the query:
UPDATE sp_CFQ_Coord_Corrections
INNER JOIN (CFQ_Coord_Corrections
INNER JOIN CFQ_Referrals ON CFQ_Coord_Corrections.CorrID = CFQ_Referrals.RecID)
ON sp_CFQ_Coord_Corrections.ID = CFQ_Referrals.RecID
SET CFQ_Coord_Corrections.MatchFound = 1,
CFQ_Coord_Corrections.RecTblID = [CFQ_Referrals].[RecTblID],
sp_CFQ_Coord_Corrections.MatchFound = 1
WHERE (((CFQ_Coord_Corrections.MatchFound)=0)
AND ((sp_CFQ_Coord_Corrections.MatchFound)=0)
AND ((CFQ_Coord_Corrections.RecImported)=1)
AND ((CFQ_Referrals.RecFileName)='COORDCORR_SPOINT')
AND ((CFQ_Referrals.RecCombKey)='No.Match')
AND ((sp_CFQ_Coord_Corrections.RecImported)=1));
Error messages seen when executed:
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'INNER'.
Msg 102, Level 15, State 1, Line 10
Incorrect syntax near 'CFQ_Coord_Corrections'.
Please help.....Below is the query:
UPDATE sp_CFQ_Coord_Corrections
INNER JOIN (CFQ_Coord_Corrections
INNER JOIN CFQ_Referrals ON CFQ_Coord_Corrections.CorrID = CFQ_Referrals.RecID)
ON sp_CFQ_Coord_Corrections.ID = CFQ_Referrals.RecID
SET CFQ_Coord_Corrections.MatchFound = 1,
CFQ_Coord_Corrections.RecTblID = [CFQ_Referrals].[RecTblID],
sp_CFQ_Coord_Corrections.MatchFound = 1
WHERE (((CFQ_Coord_Corrections.MatchFound)=0)
AND ((sp_CFQ_Coord_Corrections.MatchFound)=0)
AND ((CFQ_Coord_Corrections.RecImported)=1)
AND ((CFQ_Referrals.RecFileName)='COORDCORR_SPOINT')
AND ((CFQ_Referrals.RecCombKey)='No.Match')
AND ((sp_CFQ_Coord_Corrections.RecImported)=1));
Error messages seen when executed:
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'INNER'.
Msg 102, Level 15, State 1, Line 10
Incorrect syntax near 'CFQ_Coord_Corrections'.
Please help.....
sp_CFQ_Coord_Corrections is a table and not a stored procedure.
are these both tables "sp_CFQ_Coord_Corrections" and "CFQ_Coord_Corrections" different ??
Maybe you are looking for
-
I have downloaded latest PC software for my N70 me. I had to as I am using Windows Vista. But I am facing a peculiar problem when I try to back up files on my phone. When I try to back up data, the back up process stops at 40-50 per cent. Then I get
-
Creation of staging table - quickest way.
Hi, I need to create a staging table with roughly 370 fields. The sources' specs are not clear and some of the staging table's fields, too. So effectively, first of all I need to understand the staging fields and the source fields. The end user has b
-
Help! Ipod not starting up! Error 1611
Please help! I did all the steps in the help page: recharge, restart, update to latest itunes, replace ...nothing works! Persistent error 1611
-
Hi, I have all my videos in WMA format and it says on the itunes help thing that WMA files will work on it. But every time I try to drag the files onto it it wont even show them on there and just freezes or doesn't do anything. I looked on the proper
-
Last Purchase value of particular material in cube pur_c02
Dear Friends, I have a cube PUR_C02 and i would like to get the last purchase value of any particular Material. Can anybody help me how to get it. Thanks with regards Malik