Sql Query - Update Closing Balance

Hi
I am trying to write  a SQL Query , for the following table , I want to update Closing Balance in the table during Query refresh and it should update Closing Balance.
First Row Cl Balance : Op Balance + Receipt - Issue = Cl Balance
From Second row      :  Last row Cl Balance + Rec - Issue = Cl Balance up to the end of row .
Date
Code
Op Balance
Rec
Issue
Cl Balance
01/04/2014
10001
5000
0
0
5000
01/04/2014
10001
2000
7000
01/04/2014
10001
200
6800
01/04/2014
10001
2500
9300
05/04/2014
10001
300
9600
05/04/2014
10001
400
10000
05/04/2014
10001
2000
8000
05/04/2014
10001
100
8100
09/04/2014
10001
50
8050
10/04/2014
10001
250
8300
11/04/2014
10001
3000
5300
Thanks in advance
Sandy

Hi
Thanks for Instant Solution .
while running the script its been found that all the entries are not calculating correctly , Kindly find here below Calculated Cl Balance and the correct cl.balance
select trandate,productcode,nvl(opbal,0)opbal,
                            nvl(ptnqty,0)ptnqty,
                  nvl(waybillqty,0)waybillqty,
                nvl(clbal,0)ClBal,nvl(first_value(opbal)
over (partition by productcode order by productcode,trandate), 0 )
+ nvl(sum(ptnqty) over (partition by productcode order by productcode,trandate), 0 )
- nvl(sum(waybillqty) over (partition by productcode order by productcode,trandate), 0 )
clbalance_calculated
from fgaging where productcode = 499001
order by productcode,trandate
TRANDATE
PRODUCTCODE
NVL(OPBAL,0)
NVL(PTNQTY,0)
NVL(WAYBILLQTY,0)
NVL(CLBAL,0)
CLBALANCE_CALCULATED
Correct Cl.Balance
01-Apr-14
499001
812720
0
0
0
812720
812720
23-Apr-14
499001
0
610800
0
0
1423520
1423520
30-Apr-14
499001
0
0
1172590
0
250930
250930
31-May-14
499001
0
1641750
0
0
27330
1892680
31-May-14
499001
0
0
1865350
0
27330
27330
30-Jun-14
499001
0
1231250
0
0
729110
1258580
30-Jun-14
499001
0
0
529470
0
729110
729110
30-Jul-14
499001
0
1767500
0
0
2496610
2496610
31-Jul-14
499001
0
0
1304260
0
1192350
1192350
19-Aug-14
499001
0
702000
0
0
1894350
1894350
30-Aug-14
499001
0
0
958785
0
935565
935565
30-Sep-14
499001
0
0
743943
0
495622
191622
30-Sep-14
499001
0
304000
0
0
495622
495622
31-Oct-14
499001
0
895500
0
0
566322
1391122
31-Oct-14
499001
0
0
824800
0
566322
566322
26-Nov-14
499001
0
617300
0
0
1183622
1183622
30-Nov-14
499001
0
0
837560
0
346062
346062
29-Dec-14
499001
0
891000
0
0
1237062
1237062
31-Dec-14
499001
0
0
518000
0
719062
719062
31-Jan-15
499001
0
0
1116060
0
334002
-396998
31-Jan-15
499001
0
731000
0
0
334002
334002

Similar Messages

  • Need help in SQL Query: Update a row in a table & insert the same row into another table

    I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
    Thanks in Advance.

    Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
    SQL> var v_id number
    update tableA  
    set colB='ABC' 
    where colC='XYZ' 
    returning id into :v_id;
    insert into table A_History (ID, colA, colB, ColC)  
    select id, ColA, ColB, ColC  
    from tableA  
    where id = :v_id;   

  • Crystal Reports 10 Datasource Location and SQL Query update

    I am running Crystal Reports 10 accessing SQL Server 2008 database on Windows 7. Our product changed database names and I'm trying to update reports to point to the new database. Sounds nice and simple. The database has no structure changes yet, it's just a copy and rename of the old database. Both databases exist, same SQL instance, same permissions, etc. ...
    Existing working report:
       Has an ODBC (RDO) location to database DbVersion1
       If I run Show SQL Query, the database name is in the query text (i.e. FROM DbVersion1.dbo.MyTable)
    Attempted:
       In Set Database Location popup, I created a new ODBC (RDO) connection to database DbVersion2
       Updated Current Data Source for report to this new ODBC (RDO) connection.
       Ran Verify Database. Popup stated "The database is up to date."
    But when I run "Show SQL Query", is still shows DbVersion1 in the text, and the report displays data from DbVerison1. When I display the Datasource Location for the report, it shows DbVersion2 as I changed to above. How do I "refresh" the SQL Query to recognize the new Datasource Location?
    Thanks,
    Gary

    Hi Gary,
    A possible couple of issues, CR 10 doesn't support SQL Server 2008 and it doesn't support Windows 7. We had to update CR XI R2 SP 6 and above to make SQL 2008 work. MS changed the name of their client dll so CR is not aware of the new drivers.
    MDAC native driver may work but not sure....
    Try OLE DB, it may work better.
    Thanks
    Don

  • Is there a simple way to refresh a SQL Query (Updatable report) region

    I have a page in APex 4.1 that has many regions. I would like to be able to refresh a single region.
    Currently, I have the following
    Region (sql query updateable report).
    STATIC ID = LANDINGS
    in the region footer, I have:
    <script type="text/javascript">
    $s('P110_LANDINGS_REGION_ID','#REGION_STATIC_ID#');
    </script>
    P110_LANDINGS_REGION_ID is a hidden field.
    I use javascript to refresh....but it does not seem to be working. Previously, we had hard-coded the region id ( $a_report('1363338167540162011','1','100','100');) ...but that ID was somehow corrupted, which has lead me to the 'OMG...there must be an easier way!' lament.
    the javascript is:
    $a_report('P110_LANDINGS_REGION_ID','1','100','100');
    thanks!
    Karen
    ps. could I just directly reference the static id in my javascript...
    $a_report('LANDINGS','1','100','100');

    Karen,
    First off: please post code in &#123;code&#125;...&#123;code&#125; tags!
    function AddFavoriteSpecies()
    get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=favorite_species_collection',0);
    gReturn = get.get();
    rowCount = rowCount + parseInt(gReturn);
    pHMS_add = '&G_HMS_FLAG.';
    $a_report('1363338167540162011','1','100','100');
    //$a_report($x('P110_LANDINGS_ID').value,'1','15','15');the statement:
    $a_report('1363338167540162011','1','100','100'); works, but the statement $a_report($x('P110_LANDINGS_ID').value,'1','15','15'); does not.
    Can anyone help.
    I am assigning the page field P110_LANDINGS_ID in the footer of a region with a static id = LANDINGS.
    <script type="text/javascript">
    $s('P110_LANDINGS_ID','#REGION_STATIC_ID#');
    </script>
    Well, let's start by dumping $a_report. This is undocumented code, and it has long been replaced by triggering a refresh.
    Next, don't use $x(pNode).value to retrieve a value. Rather use $v(pNode) to do this.
    function AddFavoriteSpecies()
       get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=favorite_species_collection',0);
       gReturn = get.get();
       rowCount = rowCount + parseInt(gReturn);
       pHMS_add = '&G_HMS_FLAG.';
       //get the region id from the item
       //use it in a jQuery selector to get the region
       //trigger the refresh event on this object
       $("#" + $v('P110_LANDINGS_ID')).trigger('apexrefresh');
    }Now if you want to make sure that P110_LANDINGS_ID contains a value, add an alert with its value before you use it.
    alert('P110_LANDINGS_ID value: '+$v('P110_LANDINGS_ID'))

  • SQL query  update to the Effective Dated Row in PS_JOB table?  SQL Server

    Hi,
    I have a requirement to update the Holiday Schedule field in the maximum effective date row based on the criteria: EMPL_RCD and BUSINESS_UNIT.
    Initially I ran a select query to see how many rows will gets affected.It fetched rows properly with the criteria.
    When I am trying to update the query with the same criteria its showing error message.
    But I don't find any mistake in my query...
    Here is the query I have used:
    UPDATE PS_JOB J SET J.HOLIDAY_SCHEDULE='HLDY' WHERE
    J.EFFDT=(SELECT MAX(A.EFFDT) FROM PS_JOB A
    WHERE A.EMPLID=J.EMPLID
    AND A.EMPL_RCD=J.EMPL_RCD
    AND A.EFFDT<=GETDATE())
    AND J.EFFSEQ=
    (SELECT MAX(A1.EFFSEQ) FROM PS_JOB A1
    WHERE A1.EMPLID=J.EMPLID
    AND A1.EMPL_RCD=J.EMPL_RCD
    AND A1.EFFDT=J.EFFDT)
    AND J.BUSINESS_UNIT='HLDY1'
    AND J.EMPL_RCD=0
    Try with differnt ways but no result. Could anyone please guide me how I can update it....
    Thanks in Advance!

    My database is MY SQL server.
    I found the issue and it is working now. Update syntax works diffrently when we use alias name in set column.
    UPDATE PS_JOB SET HOLIDAY_SCHEDULE='HLDY' FROM PS_JOB J WHERE
    J.EFFDT=(SELECT MAX(A.EFFDT) FROM PS_JOB A
    WHERE A.EMPLID=J.EMPLID
    AND A.EMPL_RCD=J.EMPL_RCD
    AND A.EFFDT<=GETDATE())
    AND J.EFFSEQ=
    (SELECT MAX(A1.EFFSEQ) FROM PS_JOB A1
    WHERE A1.EMPLID=J.EMPLID
    AND A1.EMPL_RCD=J.EMPL_RCD
    AND A1.EFFDT=J.EFFDT)
    AND J.BUSINESS_UNIT='HLDY1'
    AND J.EMPL_RCD=0
    This has worked in SQL server.
    Thanks for looking into this.

  • How to add a row-selector to an existing SQL Query (updatable report)

    Hi,
    I screwed up an extensive updatable report in Apex 4.2 region by one time indicating the page may be parsed at run time.
    After setting this back (to validate query) a lot of the columns setting were gone, and also the row-selector
    I actually don't kno how to simply add this row-selector back into place.
    Anyone who can point me in the right direction?
    Thanks a lot
    Wim

    Wim,
    >
    Hi,
    I screwed up an extensive updatable report in Apex 4.2 region by one time indicating the page may be parsed at run time.
    After setting this back (to validate query) a lot of the columns setting were gone, and also the row-selector
    I actually don't kno how to simply add this row-selector back into place.
    Anyone who can point me in the right direction?Have you been able to recover all your other configuration and this is the last thing you need to fix? Or are all those other things needing to be fixed as well?
    The reason I ask is that you may want to consider just starting from scratch, if you haven't put lots of effort into recovering everything else just yet.
    On the other hand, if you just want to add a checkbox back into the SQL statement then you can add this, substituting your column name for empno of course:
    APEX_ITEM.CHECKBOX2(1,empno,'CHECKED') "Select"When you do this you'll get a warning that you're changing the interactive report, which you should accept. Then you need to make sure that the column is actually shown in the interactive report by making sure it's in the displayed columns list. And you may also need to change the display type of the column to "Standard Report Column"
    Hope that helps.
    Earl

  • Update users in Active Directory form SQL query update

    I need to update the fields in the
    Active Directory 2003 users from a
    SQL Server 2003 query. Any idea plissss???

    This is an powershell example to create AD users from SQL Server.
    The Powershell cmdlet Set-ADUser will update the AD User fields.
    $SQLText = "SELECT e.BusinessEntityID, p.Title, p.FirstName, p.MiddleName, p.LastName, p.Suffix, "+
    "e.JobTitle, d.Name AS Department, d.GroupName, edh.StartDate, e.LoginID"+
    " FROM HumanResources.Employee AS e"+
    " INNER JOIN Person.Person AS p ON p.BusinessEntityID = e.BusinessEntityID"+
    " INNER JOIN HumanResources.EmployeeDepartmentHistory AS edh ON e.BusinessEntityID = edh.BusinessEntityID"+
    " INNER JOIN HumanResources.Department AS d ON edh.DepartmentID = d.DepartmentID"+
    " WHERE (edh.EndDate IS NULL)"+
    " AND (p.FirstName ='Brian')"
    $SqlCon = New-Object System.Data.SqlClient.SqlConnection
    $SqlCon.ConnectionString = "Server=localhost;Database=AdventureWorks2012;Trusted_Connection=yes;;"
    $SqlCon.Open()
    $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
    $SqlCmd.Connection = $SqlCon
    $SqlCmd = $SqlCon.CreateCommand()
    $SQLCmd.CommandText = $SQLText
    $Result = $SQLCmd.ExecuteReader()
    $Table = New-Object System.Data.DataTable
    $table.Load($Result)
    $SqlCon.Close()
    $Password = "P@assword1"
    foreach($Item in $Table)
    $newUserID=@{
    Name=$item.FirstName+$Item.LastName
    Description="This is a test of a bulk user add"
    GivenName=$item.FirstName
    Surname=$item.LastName
    DisplayName=$item.FirstName+" "+$Item.LastName
    UserPrincipalName="$($item.FirstName+"."+$Item.LastName)@corp.contoso.com"
    EmployeeID=$item.BusinessEntityID
    ScriptPath='login.cmd'
    Company="Contoso"
    Department=$Item.Department
    EmailAddress="$($item.FirstName+"."+$Item.LastName)@corp.contoso.com"
    Title=$Item.JobTitle
    $TargetOU="OU="+$item.Department+",DC=corp,DC=contoso,DC=com"
    Try{
    $newUserID
    New-ADUser @newUserID -Path $TargetOU -ErrorAction Stop -AccountPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -Passthru
    Enable-ADAccount -Identity $newUserID.Name
    Set-ADUser -Identity $newUserID.Name -ChangePasswordAtLogon $true
    Write-Host "UserID $($newUserID.Name) created!" -ForegroundColor green
    Catch{
    Write-Host "There was a problem creating UserID $($item.UserID). The account was not created!" -ForegroundColor Red

  • SQL Query Updatable Region ?'s

    Based upon the updatable table on http://htmldb.oracle.com/pls/otn/f?p=36205:5::::RP:P5_EMPNO:7839 I would like to do the following:
    I would like to select a value in the first column (it is based on an LOV query) which is no problem..
    But I would like the second column to also be based on an LOV and of course that LOV is dependant upon the value of the first column.
    1) The second column will need to generate its values based upon the id of the first column selected.
    So for example if someone picks "Location A" I need the returned value from there in order to generate the query for the second column so that I
    can pick from all the all the available departments at that location.
    I can write the functions for the queries but what value do I send to the function/ or simply reference in the function call???
    2) Also is it possible that after a value has been selected in the first drop down that it be disabled? What I am getting at is that I
    do not want someone selecting a value from the first drop down, getting a value from the second and then changing the first, it could cause big problems...

    This is what I did and it works! I got it from Carl's website... I'll post the link when I find it...
    1.) HTML Region - to contain Javascript below.
    <script language="JavaScript1.1" type="text/javascript">
    function f_get_select_list(pthis,pSelect) {
    var l_Return = null;
    var l_Select = html_GetElement(pSelect);
    var get = new htmldb_Get(null,&APP_ID.,'APPLICATION_PROCESS=odp_campus_list',0);
    get.add('TEMPORARY_ITEM',pthis.value);
    l_Return = get.get('XML');
    if(l_Return && l_Select){
         var l_Count = l_Return.getElementsByTagName("option").length;
         l_Select.length = 0;
    for(var i=0;i<l_Count;i++){
         var l_Opt_Xml = l_Return.getElementsByTagName("option");
    appendToSelect(l_Select, l_Opt_Xml.getAttribute('value'), l_Opt_Xml.firstChild.nodeValue)
    function appendToSelect(pSelect, pValue, pContent) {
    var l_Opt = document.createElement("option");
    l_Opt.value = pValue;
    if(document.all){
              pSelect.options.add(l_Opt);
              l_Opt.innerText = pContent;
         }else{
              l_Opt.appendChild(document.createTextNode(pContent));
              pSelect.appendChild(l_Opt);
    </script>
    2.) Create Hidden Text Item - TEMPORARY_ITEM
    3.) Create a Application Process
    a. Go to Shared Components
    b. Application Processes
    c. Create a process
    On Demand: Run this application process when requested by a page process.
    Name - dependant on the select
    Ex: odp_campus_list
    Type: PL/SQL Anonomous Block
    No conditions
    declare
         l_counter number := 0;
         l_o_name varchar2(2000);
         encoded varchar2(50);
         begin
         owa_util.mime_header('text/xml', FALSE );
         htp.p('Cache-Control: no-cache');
         htp.p('Pragma: no-cache');
         owa_util.http_header_close;
         --insert into debugtab values ('otn_Select_XML:'||:TEMPORARY_ITEM, sysdate);
         --commit;
         htp.prn('<select>');
         for rec in (
         select "CCC_DDD" as "ID", "DISTRICT_NAME" as "NAME"
         from "LS_DISTRICT" where "REGION_NUMBER" = :TEMPORARY_ITEM) loop
         htp.prn('<option value="' || rec.id || '">' ||F_REPLACE_SPECIAL_CHARS(rec.name)|| '</option>');
         l_counter := l_counter + 1;
         end loop;
         htp.prn('</select>');
         insert into debugtab values ('otn_Select_XML.Count:'||l_counter, sysdate);
         commit;
         end;
    4.) Add "onchange" statement to the first Select List
    onChange="javascript:f_get_select_list(this,'P_DISTRICT');"
    Ex: P_DISTRICT above is to be replaced with your second select list item name.
    BillC :>)

  • SQL query - update table

    I have 2 tables:
    customer table with custno and deptcode
    income table with custno and deptcode
    how can I update the deptcode in the income table,
    if customer.custno = income.custno ?
    thanks.
    andrew

    I have 2 tables:
    customer table with custno and deptcode
    income table with custno and deptcode
    how can I update the deptcode in the income table,
    if customer.custno = income.custno ?
    thanks.
    andrewUPDATE income A SET A.deptcode = (SELECT deptno FROM customer where custno = A.custno) WHERE A.custno = (SELECT custno FROM customer where custno = A.custno)

  • SQL Query (updateable report) CheckBox Update Problem

    My process will update 1 or 2 rows, but fails on three or more rows. All the rows on the page can be processed, up to 2 at a time.
    The SQL Query Report can have 50 rows on a page. Only the check box and the hidden primary key column are returned by the report to the process (marked as edit).
    If I issue the update myself, I can update any number of rows with no error.
    If I change the update SQL to a select, it works for the all of the checked lines (the correct count is displayed in the process message.
    The only thing I see for the failure is a url
    http://d101dbaxeaa2llb:10700/apex/wwv_flow.accept
    Process is:
    DECLARE
    vRow BINARY_INTEGER;
    item NUMBER;
    BEGIN
    item := 0;
    FOR i IN 1 .. apex_application.g_f01.COUNT
    LOOP
    item := item + 1;
    vRow := apex_application.g_f01(i);
    update #OWNER#.B_ATT_DAYS_FUT
    set day_status_cd =
    case
    when day_status_cd = -1 and day_dt is not null then 2
    when day_status_cd = -1 and day_dt is null then 0
    when day_status_cd = 6 then 7
    else 2
    end
    where days_pk = to_number(apex_application.g_f02 (vRow));
    END LOOP;
    :P35_CHECKED_CT := item;
    END;
    This is in APEX Application Express 3.1.0.00.32 on Oracle 11.1.0.6.0.

    Query is at the end. The Report Regions is a SQL Query (Updatable Report).
    I don't thinks this is my code problem.
    The system I'm using is dieing. It has had two disk crashes, which spinrite brought back. I've restored from a partition image and a full cold backup. Then I've had a number of blue screen failures. One of the DBAs working for me rebuilt the 11g instance on a VM and restored the cold backup. Everything runs fine there. I even applied the latest code export from the failing systems development workspace to the VM based system. Still runs fine.
    There are a number of abends in the alert log ORA-07445 and ORA-21779 for which our on-site ASC Engineer has opened a TAR/SR. I suspect that some part of one of the FLOW tablespaces was damaged, a part which deals with runtime APEX. Build time is running fine. Application just does not, either as a runtime or in the development system.
    We are moving to a new AIX server, just finishing the setup and then I can send over the exports. That should put this to bed.
    SELECT
    DAYS_PK
    , NAME_TX
    , DAY_CD
    , DAY_DESC_TX
    , DAY_STATUS_CD
    , DAY_STATUS_DESC_TX
    , DAY_DT
    , REASON_TX
    , TEN_DAY_PERIOD_FL
    , EARNED_ON_DT
    , EXPIRES_ON_DT
    , PLANNED_ON_DT
    , GUARANTEED_DAY_CD
    , GUARANTOR
    FROM
    (SELECT
    DAYS."DAYS_PK"
    , A_ATT_USERS.NAME_TX
    , DAYS."DAY_CD"
    , DAY_CD."DAY_DESC_TX"
    , DAYS."DAY_STATUS_CD"
    , DAY_ST_CD."DAY_STATUS_DESC_TX"
    , DAYS."DAY_DT"
    , DAYS."REASON_TX"
    , DAYS."TEN_DAY_PERIOD_FL"
    , DAYS."EARNED_ON_DT"
    , DAYS."EXPIRES_ON_DT"
    , DAYS."PLANNED_ON_DT"
    , CASE DAYS."GUARANTEED_DAY_CD"
    WHEN 'E' THEN 'GUARANTEED'
    WHEN 'R' THEN 'GUARANTOR'
    ELSE NULL
    END GUARANTEED_DAY_CD
    , G_ATT_USERS.NAME_TX "GUARANTOR"
    FROM
    "B_ATT_DAYS_FUT" DAYS
    LEFT OUTER JOIN "A_ATT_USERS" G_ATT_USERS
    ON
    "DAYS"."GUARANTEED_COMIT_ID" = "G_ATT_USERS"."COMIT_ID"
    LEFT OUTER JOIN "A_ATT_USERS"
    ON
    "DAYS"."COMIT_ID" = "A_ATT_USERS"."COMIT_ID"
    , "T_ATT_DAY_CD" DAY_CD
    , "T_ATT_DAY_STATUS_CD" DAY_ST_CD
    WHERE
    DAYS."DAY_CD" = DAY_CD."DAY_CD"
    AND DAYS."DAY_STATUS_CD" = DAY_ST_CD."DAY_STATUS_CD"
    AND DAYS.COMIT_ID IN
    SELECT DISTINCT
    ( R.COMIT_ID )
    FROM
    ATT_ATTENDANCE.A_ATT_STAFF_ROLE R
    WHERE
    R.COMIT_ID <> :P1_COMIT_ID_HIERARCHY START
    WITH R.COMIT_ID = :P1_COMIT_ID_HIERARCHY
    CONNECT BY PRIOR R.COMIT_ID = R.MGR_COMIT_ID
    AND DAYS.DAY_STATUS_CD IN ( 1, -1, 6 )
    AND DAYS.COMIT_ID <> :P1_COMIT_ID
    ORDER BY
    A_ATT_USERS.NAME_TX
    , DAYS.DAY_DT
    , DAYS.DAY_CD DESC
    , DAYS.EARNED_ON_DT)
    WHERE
    INSTR(UPPER(NAME_TX),UPPER(COALESCE(:P35_S_NAME,NAME_TX))) > 0

  • Need help in improving the performance for the sql query

    Thanks in advance for helping me.
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. The data count which is updated in the target table is 2 million records and the target table has 15 million records.
    Any suggestions or solutions for improving performance are appreciated
    SQL query:
    update targettable tt
    set mnop = 'G',
    where ( x,y,z ) in
    select a.x, a.y,a.z
    from table1 a
    where (a.x, a.y,a.z) not in (
    select b.x,b.y,b.z
    from table2 b
    where 'O' = b.defg
    and mnop = 'P'
    and hijkl = 'UVW';

    987981 wrote:
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. And that meant what? Surely if you spend all that time and effort to try various approaches, it should mean something? Failures are as important teachers as successes. You need to learn from failures too. :-)
    The data count which is updated in the target table is 2 million records and the target table has 15 million records.Tables have rows btw, not records. Database people tend to get upset when rows are called records, as records exist in files and a database is not a mere collection of records and files.
    The failure to find a single faster method with the approaches you tried, points to that you do not know what the actual performance problem is. And without knowing the problem, you still went ahead, guns blazing.
    The very first step in dealing with any software engineering problem, is to identify the problem. Seeing the symptoms (slow performance) is still a long way from problem identification.
    Part of identifying the performance problem, is understanding the workload. Just what does the code task the database to do?
    From your comments, it needs to find 2 million rows from 15 million rows. Change these rows. And then write 2 million rows back to disk.
    That is not a small workload. Simple example. Let's say that the 2 million row find is 1ms/row and the 2 million row write is also 1ms/row. This means a 66 minute workload. Due to the number of rows, an increase in time/row either way, will potentially have 2 million fold impact.
    So where is the performance problem? Time spend finding the 2 million rows (where other tables need to be read, indexes used, etc)? Time spend writing the 2 million rows (where triggers and indexes need to be fired and maintained)? Both?

  • ORA-01008 on SQL Query

    Hello from IOUG-A!!
    OK, I have a SQL Query updatable report region that I've written the following SQL for:
    select per_name, per_address_line1, per_town, per_isle_code, per_cntry_code
    from gen_persons
    where
    (per_last_name like nvl(v(:P4200_LAST_NAME),
    '---')||'%' ) and
    (per_first_name like nvl(v(:p4200_FIRST_NAME),
    '---')||'%')
    ) or
    per_name like nvl(v(:P4200_LAST_NAME),
    '---')||'%' )
    This works great as long as P4200_FIRST_NAME is not NULL. If P4200_FIRST_NAME is NULL, I get the following error when I run the report:
    report error:
    ORA-01008: not all variables bound
    My guess is that this is because of the NVL replacement and P3200_FIRST_NAME that is taking place, but I'm not sure how to fix it. Any ideas?
    Robert

    Robert,
    Change '--' to '-'||'-'. Our parser thinks '--' is the beginning of a line comment.
    Scott

  • Query to claculate balance owed to a suuplier

    Dear All
    can any one provide me with Sql Query to claculate balance owed to a supplier.
    Best Regards
    Arifuddin

    Hi,
    It's not very clear what you wish to display as balance for a given date range.
    It depends on how you've configured your balances and periods and which balance you're referring to.
    The API allows for a given date only which corresponds to the earned date.
    Let's say, for example, you have a balance 'Basic Salary' defined with a dimension 'Assignment Processing Period To Date' and feed the element corresponding to Basic Salary.
    If you need to get the "Total Basic Salary" (balance ?) for the period '01-Feb-2015' to '31-Mar-2015', then you need to get the earned dates for the Payroll runs done during this period and call the above package with the appropriate parameters.
    Another means is by querying the tables/views directly: you could use, for example - this might be easier in your situation:
       select sum (nvl (pbv.value, 0))
         from pay_balance_values_v pbv
        where pbv.balance_name = 'Basic Salary'
          and pbv.database_item_suffix = '_ASG_PTD'
          and pbv.assignment_id = <your_assignment_id>
          and pbv.effective_date between  to_date('01/02/2015','dd/mm/yyyy')
          and to_date('31/03/2015','dd/mm/yyyy');
    Regards,
    Rajen

  • Insert and update query to calculate the opening and closing balance

    create table purchase(productid number(5) ,dateofpurchase date,
    qty number(5));
    create table inventory(invid number(5),productid number(5),
    idate date,openingqty number(5),closingqty number(5));
    Records in inventory:
    1,1,'01-jan-2009', 10, 20
    2,1,'03-jan-2009', 20, 30
    3,1,'04-jan-2009', 40, 50
    when I enter the purchase invoice for 15 qty on 02-jan-2009
    after say '15-jan-09' , a new record should get inserted
    with opening balance = (closing balance before 02-jan-2009)
    and all the opening and closing balance for that product should
    get affected.
    If the invoice for 20 qty is entered for the existing date say
    '03-jan-2009' in inventory , then the closing balance
    for 03-jan-2009 should get updated and all the following records
    should get affected.
    I need the insert for the first one and update query for the
    second one.
    Vinodh

    <strike>You can do this in one statement by using the merge statement</strike>
    Hmm, maybe I spoke too soon.
    Edited by: Boneist on 25-Sep-2009 13:56
    Thinking about it, why do you want to design your system like this?
    Why not simply have your purchases table hold the required information and then either work out the inventory on the fly, or have a job that calls a procedure to add a row for the previous day?
    If you continue with this design, you're opening yourself up to a world of pain - what happens when the data doesn't match the purchases table? Also when is the inventory cut-off to reset the opening/closing balances? Monthly? Annually? Weekly? If it's set to one of those, what happens when the business request the inventory for a particular week?
    Edited by: Boneist on 25-Sep-2009 13:59

  • Update Next Shift opeing balance with current shift closing balance

    hi,
     I have an aggregation table which have shiftwise, productwise, warehouse wise stock data. i want update the next shift opening balance with current  shift closing balance.
    My table is
    ID          ShiftDate         ShiftNumber   ProductID   OpeningBalance  Inward  Outward  ClosingBalance WarehouseID
    1             2014-07-02         1                  1                  
    0                   50           20                
    30                1
    2             2014-07-02          2                 1                  
    50                   0              0                
    50               1 
    Actually my aggregation is already run and update the table like above. But after that user done a transaction and accounted in the first shift. So i need to reupdate the data after the accountshift. I update the outward and closing balance so the closing
    balance of first shift is correct.
    Now i want update opening balance of second shift needs to be updated based on the corresponding closing balance of the shift 1.
    Please guide me for this. I can pass ShiftData and ShiftNumber as '2014-07-02' and 1 respectively.

    Which is sql server version you'e using? If its sql 2012, you can use PARTITION BY with RANGE BETWEEN for this. 
    Otherwise you need to use a correlated subquery logic using APPLY
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

Maybe you are looking for

  • Can no longer transfer iphone pictures to pc

    Please Help!   I have read through dozens of responses in your forum about the transfer of iPhone photographs to a PC.that does no good because the responses are conflicting. What makes me scratch my head the most is that apparently no one is aware t

  • HT201938 connecting MacBook Pro (15-inch, Mid 2009) to Hisense TV with audio?!?!!?

    hello everyone. if anyone is familar with successfully getting the older macbook pros that dont support audio out to stream and preform digital audio on a TV or has any helpful information that will get me familiar with trying to successfully stream

  • Count days in a month for a date range

    i am trying to find no. of days between 2 Date Ranges for a list of Ids. i used the logic in the below link: count days of the month My query is giving duplicates since, I have list of Ids. Doctor_ID     Patient_ID     ARRIVE_DT_TM     DISCH_DT_TM 75

  • Weird dv files

    I recently reinstalled my computer and had to move two captured movie files around. They were captured on another computer via Final Cut Pro and had no extension, but they did have QT icons. I guess they were .dv files. I remember importing them into

  • ITunes 9 has corrupted my iPod Classic

    So here is my sorry story - please let me know if you have had similar symptoms and if you have found a solution. I have a MacBook Pro, running Snow Leopard. I recently upgraded iTunes to iTunes version 9.0.2 and attempted to synchronise my iPod Clas