How to convert this select statement into update

Hai All
I have two table Namely Daily_attend , Train_mast
Daily_attend Consist Of fields are Train_mast consist Of fields are
Name varchar Train no var
Empcode Num T_date date
Intime Date Train_name var
Outtime date Late_hrs var
IND_IN Number
IDE_OUT Number
Attend_date date
I need to update IDE_IN In Daily_attend table Depend upon late_hrs in the Train_mast table
I have got Through in select statement This is my select statement
select to_number(TO_DATE(TO_CHAR(Intime,'DD-MON-YYYY')||' '||
TO_CHAR(0815,'0000'),'DD-MON-YYYY HH24:MI')+late_hrs/(24*60)-intime
) * 24*60 from dail_Att,train_mast;
How can i convert it to update
Any help is highly appricateable
Thanks In Advance
Regards
Srikkanth.M

Srikkanth,
Try this code. And 1 more thing, i can't see any WHERE condition to join between the 2 tables DAIL_ATT, TRAIN_MAST.
UPDATE DAIL_ATT A SET A.IDE_IN = (SELECT TO_NUMBER(TO_DATE(TO_CHAR(INTIME, 'DD-MON-YYYY')|| ' ' || TO_CHAR(0815, '0000'), 'DD-MON-YYYY HH24:MI') + LATE_HRS / (24 * 60) - INTIME) * 24 * 60 FROM TRAIN_MAST B WHERE <condition>);Regards,
Manu.
If my response or the response of another was helpful or Correct, please mark it accordingly

Similar Messages

  • How to optimize this select statement  its a simple select....

    how to optimize this select statement  as the records in earlier table is abt i million
    and this simplet select statement is not executing and taking lot of time
      SELECT  guid  
                    stcts      
      INTO table gt_corcts
      FROM   corcts
      FOR all entries in gt_mege
      WHERE  /sapsll/corcts~stcts = gt_mege-ctsex
      and /sapsll/corcts~guid_pobj = gt_Sagmeld-guid_pobj.
    regards
    Arora

    Hi Arora,
    Using Package size is very simple and you can avoid the time out and as well as the problem because of memory.  Some time if you have too many records in the internal table, then you will get a short dump called TSV_TNEW_PAGE_ALLOC_FAILED.
    Below is the sample code.
    DATA p_size = 50000
    SELECT field1 field2 field3
       INTO TABLE itab1 PACKAGE SIZE p_size
       FROM dtab
       WHERE <condition>
    Other logic or process on the internal table itab1
    FREE itab1.
    ENDSELECT.
    Here the only problem is you have to put the ENDSELECT.
    How it works
    In the first select it will select 50000 records ( or the p_size you gave).  That will be in the internal table itab1.
    In the second select it will clear the 50000 records already there and append next 50000 records from the database table.
    So care should be taken to do all the logic or process with in select and endselect.
    Some ABAP standards may not allow you to use select-endselect.  But this is the best way to handle huge data without short dumps and memory related problems. 
    I am using this approach.  My data is much more huge than yours.  At an average of atleast 5 millions records per select.
    Good luck and hope this help you.
    Regards,
    Kasthuri Rangan Srinivasan

  • How to convert this BSO formulas into ASO formulas ?

    I need some help to convert this BSO formulas into ASO formulas:
    BSO formulas:
    12*("Head Count"->"Terminated"/((@PRIOR("Head Count"-> "Total Active & Leave")+"Head Count"->"Total Active & Leave")/2));
    "Head Count" is a member of the Account dimension
    "Terminated" and "Total Active & Leave" are members of the Status dimension
    Existing Active
    New Hire
    Active
    MAT
    STD
    OTH
    Leave
    Total Active & Leave
    Voluntary
    Involuntary
    Death
    Retirement
    End of Temp Assignment
    Terminated
    LTD
    Total Status
    Promotion Within Level
    Promotion to Higher Level
    Promotion
    No Total Status
    All Status
    Status (Dimension)
    In ASO, the formulas will be ??
    Thanks

    Try
    CASE WHEN IS([Period].CurrentMember, [Jan]) THEN
    12 * (([Head Count], [Terminated] ) /
    ((( [Head Count], [Total Active & Leave], [Dec], [Year].CurrentMember.lag(1) ) +
    ([Head Count], [Total Active & Leave])) / 2))
    ELSE
    12 * (([Head Count], [Terminated] ) /
    ((( [Head Count], [Total Active & Leave], [Time].CurrentMember.lag(1) ) +
    ([Head Count], [Total Active & Leave])) / 2))
    ENDTake note this assumes your Year dimension is in descending order
    Year
    --2007
    --2008
    --2009
    If Year is in Ascending order
    Year
    --2009
    --2008
    --2007
    Then you need to change
    [Year].CurrentMember.lag(1) to
    [Year].CurrentMember.lead(1)

  • Converting SELECT Statement into UPDATE

    Hi All,
    Running SQL Server 2008 R2.  I have the following SELECT query, which is returning the desired results.
    SELECT DISTINCT
    [x].[AccountNo],
    [x].[AvgAccountLen],
    CASE
    WHEN LEN([AccountNo]) > 6 THEN LEFT([AccountNo], 6)
    ELSE [AccountNo] + REPLICATE('0', [AvgAccountLen] - LEN([AccountNo]))
    END AS [NewAccountNo]
    FROM
    SELECT DISTINCT
    [AccountNo],
    SELECT TOP 1
    LEN([AccountNo])
    FROM
    [dbo].[Table]
    WHERE
    [AccountNo] > 0
    GROUP BY
    [AccountNo]
    ORDER BY
    COUNT(*) DESC
    ) AS [AvgAccountLen]
    FROM
    [dbo].[Table]
    ) AS [x]
    WHERE
    LEN([AccountNo]) <> [AvgAccountLen]
    Below are results, which again are what I'm looking for.
    AccountNo AvgAccountLen NewAccountNo
    4200 6 420000
    4250 6 425000
    42000 6 420000
    4030 6 403000
    4460 6 446000
    4250000 6 425000
    4520000 6 452000
    Long story short is that I've been left to clean up a partially-completed task.  I need to conduct an update on Table that pads (or trims) the account numbers accordingly.  Further, this process affects multiple entities which is why I can't simply
    use a static pad/trim value of 6 (this particular entity returns 6, there could be other entities with 4, 8, etc.).  AvgAccountLen may not be the most appropriate column name either - it's a representation of the most frequently-occurring value length
    (I have already confirmed that the result returned for this value is correct in each entity).  How would I go about writing a UPDATE statement to accomplish this?
    Any help is greatly appreciated!
    Best Regards
    Brad

    Can you provide your example data as a table to compliment your expected result?
    I'm thinking something like this may help:
    DECLARE @accounts TABLE (accountNo INT, avgAccountLen INT, newAccountNumber INT)
    INSERT INTO @accounts (accountNo, avgAccountLen) VALUES
    (4200 , 6),
    (4250 , 6),
    (42000 , 6),
    (4030 , 6),
    (4460 , 6),
    (4250000, 6),
    (4520000, 6)
    UPDATE @accounts
    SET newAccountNumber = LEFT(CAST(accountNo AS VARCHAR)+REPLICATE('0',avgAccountLen),avgAccountLen)
    FROM @accounts
    SELECT *
    FROM @accounts
    Don't forget to mark helpful posts, and answers. It helps others to find relevant posts to the same question.

  • How to make this select statement faster?

    this statement is really taking long time to process.
    in bseg table as vbeln is not primary key or seconday key, i guess thz the reason it is taking so much time ,,,
    can anyone help me to sort this out... ??
    any fun mod to get the data of bseg cluster table by giving vbeln?/
    or any other conditions to reduce the processing time?
    clear t_vbrkvbrp.
    sort t_vbrkvbrp by vbeln.
    loop at t_vbrkvbrp.
    at new vbeln.
    select bukrs belnr vbeln
           from bseg
           into corresponding fields of table t_temp
           where bukrs = t_vbrkvbrp-bukrs
            and vbeln = t_vbrkvbrp-vbeln.
    endat.
    endloop.
    SELECT bukrs belnr buzid koart shkzg dmbtr vbeln hkont kunnr werks
           FROM bseg
           INTO TABLE t_bseg
           for all entries in t_temp
           WHERE hkont IN s_hkont
           AND bukrs = t_temp-bukrs
           AND belnr = t_temp-belnr
           AND buzid = ' '
           AND koart = 'S'
           AND shkzg = 'H'.
    i need to get the g/l account number for the above condition type so i have to use bseg table
    Message was edited by:
            shahid mohammed syed

    Shahid,
    Usually BSEG SELECTs are slow as it is a Clu8ster table. More over you are not passing the PKeys in the WHERE condition. That's alcso one reason for slow retrieval. You can also use the table BSIS (Accounting: Secondary Index for G/L Accounts) for the G/L accounts. But first of all, I suggest you cnange your where condition as below:
    SELECT bukrs belnr buzid koart shkzg dmbtr vbeln hkont kunnr werks
    FROM bseg
    INTO TABLE t_bseg
    for all entries in t_temp
    WHERE  bukrs = t_temp-bukrs
    AND belnr = t_temp-belnr
    AND buzid = ' '
    AND koart = 'S'
    AND shkzg = 'H'
    <b>AND hkont IN s_hkont.</b>
    Not much diff. I just re-ordered the condition based on the order of BSEG fields... Lemme know if it helps.
    Regards,
    Karthik
    Message was edited by:
            Karthik

  • Is it possible to convert only select statement into procedure in Oracle

    Hi, Just i wanted to convert the below query in to procedure.Procedure input is 'P.Column1'
    SELECT
    P.Column1 AS PRODUCT,
    D.Column2 AS Column2N,
    D.Column3 AS LongColumn2iption,
    P.Column4 AS PRODUCICE,
    D.Column5 AS BilliuctID,
    E.Column6 As Impaenue,
    C.Column7 AS EffecDATE,
    FROM Table1 P, Table2 D,Table3 E,Table4 C
    WHERE
    P.Column1=D.Column1 and
    P.Column1=C.PROD_COMPONENT_ID and
    P.SETID=D.SETID and
    D.Setid =E.Setid and
    P.Setid =E.Setid and
    P.Setid =C.Setid and
    D.Column1=E.Column1 and
    P.Column1=E.Column1 and
    C.Column1<>'CONSUMER TARIFFS' and
    P.Column1 in('')

    Something like:
    SQL> var my_Data refcursor
    -- Anonymous block
    SQL> begin
      2  open :my_data for select 1,2 from dual;
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> print :my_Data
             1          2
             1          2You can then convert the above anonymous block in to a procedure.

  • How to Correct this Select Statement...?

    hi all
    i wrote a select as follows
    select datediff('HH',to_date(job_start,'hh24:mi:ss'),to_date('15:29:59','hh24:MI:ss')) from shift
    requirement is to calculate the hours used in a shift, the job_start column is date type and having value '23/08/2007 07:00:00' , and the second one is the shift end time. so it should give 8.5 hrs as the result. but it is throwing error ORA--1858 non-numeric char found where a numeric expected. datediff function is taken from Ask Tom discussion forums.
    any idea...?
    regards
    Kris

    I think i cant, this is to be done for every day...so
    is there any way i can set the time of the current
    date to '15:29:59'..?
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select to_date('23/08/2007 08:30:00','dd/mm/yyyy hh24:mi:ss') as start_time from dual)
      2  -- end of test data
      3  select (to_date(to_char(sysdate,'dd/mm/yyyy')||'  15:29:59','dd/mm/yyyy hh24:mi:ss')-start_time)*24 as hrs
      4* from t
    SQL> /
           HRS
    6.99972222
    SQL>

  • How to convert this VB code into c#

    Public Property Cell(ByVal row_index As Integer, ByVal col_index As Integer) As Object
    Get
    Return _excel.Cells(row_index, col_index).value
    End Get
    Set(ByVal value As Object)
    _excel.Cells(row_index, col_index).value = value
    End Set
    End Property
    Thanks.

    If you want to have a property called Cell that returns excel's Cells collection (which is a Range) then just do this:
    public Range Cells
    public get
    return _excel.Cells;
    // Range is accessed by .Cells
    // Range has an index operator [,]
    // so you can access .Cells[row,col]
    If you want to intercept the indexing, then you must return a object that proxies the indexing.
    class MyRange
    public MyRange( Range range ) { this.range = range; }
    Range range;
    // This just might be the syntax you're actually looking for
    public object this[int row, int col]
    get {
    return range[row,col];
    set
    range[row,col] = value;
    public MyRange Cells
    get {
    return new MyRange( _excel.Cells );

  • How to convert simple SQL Select statements into Stored Procedures?

    Hi,
    How can I convert following SELECT statement into a Stored Procedure?
    SELECT a.empno, b.deptno
    FROM emp a, dept b
    WHERE a.deptno=b.deptno;
    Thanking in advance.
    Wajid

    stored procedure is nothing but a named PL/SQL block
    so you can do it like this see below example
    SQL> create or replace procedure emp_details is
      2  cursor c1 is SELECT a.empno, b.deptno
      3  FROM scott.emp a, scott.dept b
      4  WHERE a.deptno=b.deptno;
      5  begin for c2 in c1
      6  LOOP
      7  dbms_output.put_line('name is '||c2.empno);
      8  dbms_output.put_line('deptno is ' ||c2.deptno);
      9  END LOOP;
    10  END;
    11  /
    Procedure created.and to call it use like below
    SQL> begin
      2  emp_details;
      3  end;
      4  /
    PL/SQL procedure successfully completed.
    SQL> set serveroutput on;
    SQL> /
    empno is 7839
    deptno is 10
    empno is 7698
    deptno is 30
    empno is 7782
    deptno is 10
    empno is 7566
    deptno is 20
    empno is 7654
    deptno is 30
    empno is 7499
    deptno is 30
    empno is 7844
    deptno is 30
    empno is 7900
    deptno is 30
    empno is 7521
    deptno is 30
    empno is 7902
    deptno is 20
    empno is 7369
    deptno is 20
    empno is 7788
    deptno is 20
    empno is 7876
    deptno is 20
    empno is 7934
    deptno is 10Edited by: Qwerty on Sep 17, 2009 8:37 PM

  • How to use bind variable in this select statement

    Hi,
    I have created this procedure where table name and fieldname is variable as they vary, therefore i passed them as parameter. This procedure will trim leading (.) if first five char is '.THE''. The procedure performs the required task. I want to make select statement with bind variable is there any possibility to use a bind variable in this select statement.
    the procedure is given below:
    create or replace procedure test(tablename in varchar2, fieldname IN varchar2)
    authid current_user
    is
    type poicurtype is ref cursor;
    poi_cur poicurtype;
    sqlst varchar2(250);
    THEVALUE NUMBER;
    begin
         sqlst:='SELECT EMPNO FROM '||TABLENAME||' WHERE SUBSTR('||FIELDNAME||',1,5)=''.THE ''';
         DBMS_OUTPUT.PUT_LINE(SQLST);
    OPEN POI_CUR FOR SQLST ;
    LOOP
         FETCH POI_CUR INTO THEVALUE;
              EXIT WHEN POI_CUR%NOTFOUND;
              DBMS_OUTPUT.PUT_LINE(THEVALUE);
              SQLST:='UPDATE '||TABLENAME|| ' SET '||FIELDNAME||'=LTRIM('||FIELDNAME||',''.'')';
              SQLST:=SQLST|| ' WHERE EMPNO=:X';
              DBMS_OUTPUT.PUT_LINE(SQLST);
                   EXECUTE IMMEDIATE SQLST USING THEVALUE;
    END LOOP;
    COMMIT;
    END TEST;
    Best Regards,

    So you want to amend each row individually? Is there some reason you're trying to make this procedure run as slow as possible?
    create or replace procedure test (tablename in varchar2, fieldname in varchar2)
    authid current_user
    is
       sqlst      varchar2 (250);
       thevalue   number := 1234;
    begin
       sqlst := 'update ' || tablename || ' set ' || fieldname || '= ltrim(' || fieldname || ',''.'')  where substr(' || fieldname
          || ',1,5) = ''.THE ''';
       dbms_output.put_line (sqlst);
       execute immediate sqlst;
    end test;will update every row that satisfies the criteria in a single statement. If there are 10 rows that start with '.THE ' then it will update 10 rows.

  • In how many ways we can filter this select statement to improve performance

    Hi Experts,
    This select statement taking 2.5 hrs in production, Can we filter the where condition, to improve the performance.Plz suggest with coding ASAP.
    select * from dfkkop into  table t_dfkkop
               where   vtref   like 'EPC%'        and
                   ( ( augbd      =  '00000000'   and
                       xragl      = 'X' )
                               or
                     ( augbd between w_clrfr and  w_clrto )  )  and
                       augrd      ne '03'         and
                       zwage_type in s_wtype .
    Regards,
    Sam.

    if it really takes 2.5 hours, try the followingtry to run the SQL trace and
    select *
              into table t_dfkkop
              from dfkkop
              where vtref like 'EPC%'
              and augbd = '00000000' and xragl
             and augrd ne '03'
             and zwage_type in s_wtype .
    select *
              appending table t_dfkkop
              from dfkkop
              where vtref like 'EPC%'
             and augbd between w_clrfr and w_clrto 
             and augrd ne '03'
             and zwage_type in s_wtype .
    Do a DESCRIBE TABLE after the first SELECT and after the second,
    or run an SQL Trace.
    What is time needed for both parts, how many records come back, which index is used.
    Siegfried

  • I can't find this anywhere... how to convert mp3 (not music) into text without spending much $$$.

    i can't find this anywhere... how to convert mp3 (not music) into text without spending much $$$.

    function(){return A.apply(null,[this].concat($A(arguments)))}
    hope1hope2 wrote:
    i can't find this anywhere... how to convert mp3 (not music) into text without spending much $$$.
    It's very unlikely that you'l
    l find any help here; this forum is used only
    for testing purposes. Unfortunately, I cannot suggest
    another forum
    Extra line breaks kindly supplied by the software.

  • How to convert data from rows into columns

    Hi,
    I have a sql table and the data looks like this
    GLYEAR GLMN01 GLMN02 GLMN03 GLMN04
    2007 -109712.40 6909.15 4758.72 56.88
    2007 -13411.32 19132.9 -5585.07 4362.64
    Where GLyear reprsents Year and GLMN01 is February, GLMN02 is March and so on,
    Now i want my output to be something like this which i want to insert into another table
    GLYear GLMonth GLAmount
    2007 February -109712.40
    2007 March 6909.15
    2007 April 56.88
    My new table has 3 columns, GLYear,GLMonth,GLAmount.
    Can someone please help me with the select statement on how to do this, i can work with the inserts.
    Thanks.

    I want you to check these form tread they have the same discussion as you.  They will definitely solve your problem
    http://blog.jontav.com/post/8344518585/convert-rows-to-columns-columns-to-rows-in-sql-server
    http://dba.stackexchange.com/questions/19057/convert-rows-to-columns-using-pivot-in-sql-server-when-columns-are-string-data
    http://stackoverflow.com/questions/18612326/how-to-convert-multiple-row-data-into-column-data-in-sql-server
    I hope this helps you in solving your problem. 
    Please remember to click “Mark as Answer” on the post that has answered your question as it is very relevant to other community members dealing with same problem in seeking the right answer

  • How to convert a word document into the PDF format?

    Please instruct me step by step on how to convert several Word documents into the PDF format?

    If properly installed and updated (depending on the WORD version), you can simply do any of the following:
    1. Open the doc in WORD and select Print, choose the Adobe PDF printer, print.
    2. Open the doc in WORD and go to the Acrobat menu in WORD and select create PDF (this uses PDF Maker).
    3. Open the doc in Acrobat and the conversion should be done based on PDF Maker.

  • How to execute a SELECT statement  in java??

    Hello !!
    In my java program , i need to delete a record of number X, so
    i accept the number X from the keyboard
    Then before deleting it
    i want the program to show me the name, age of the record which has the number X
    How to do this

    hello kylas
    actually i didnt get why this program example?? wats
    its executing ??? Look at reply #3 in your other thread:
    http://forum.java.sun.com/thread.jspa?threadID=713289&messageID=4126346
    Notice the similarity? You've now asked "How to delete a record in Java" and "how to execute a select statement in java". You may have noticed that, aside from the SQL and the call to execute and executeUpdate (for delete) it's the same code. This is because you don't so much do these things in Java, you do them in SQL. The Java code simply asks the Driver to execute whatever SQL you write. So, I really hope your next post isn't "how do I execute an UPDATE statement in Java".
    Good Luck
    Lee

Maybe you are looking for

  • Places to save memory space on a MacBook pro?

    I need to free up 10 gb of space on my MacBook pro, is there any easy places to save disc space?

  • Usage report is avalaible after 48 hours

    Hi expert, I have two Sharepoint 2013 on premise farms (Prod & PreProd). I have the same issue on both farms and try to figure out what could be wrong or what could I do to obtain the result I want. When I export the excel "Report usage", result is a

  • DBMS_METADATA Package Body won't compile

    I get a PLS-00103 error when attempting to complile the package body for SYS.DBMS_METADATA. The body hasn't been modified so I'm not sure where to look.

  • [b]Version mismatch problem[/b]

    Hi My application will run fine on JDK 1.3.2,Other than this version it will give this following exception if i run java.security.InvalidKeyException: Illegal key size or default parameters at javax.crypto.Cipher.a(DashoA12275) at javax.crypto.Cipher

  • Sluggish performance - Mac Mini and MBP?

    I'm experiencing sluggish performance on my Mac Mini with Leopard (upgrade installation) when using the genie effect, expose, spaces, gadgets, 3d dock, etc. It's jerky, as if the animation is missing frames. Is it related to the graphics card? I also