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.

Similar Messages

  • Query to find the no of columns in a table

    Is there a query to find the total number of columns in a table?

    Dou you know read?
    -- the number of rows in a table named yourtable:
    select count(1) from yourtable;
    -- the number of columns in a table
    -- If is a user's table:
    select count(1)
    from user_tab_columns
    where table_name='YOURTABLE'
    --If it is´t
    select count(1)
    from DBA_tab_columns
    where owner = 'USEROWNER'
    and table_name='YOURTABLE'

  • Find the latest updated or the latest inserted record  in a table

    Hi All,
    Thanks in advance
    Just a simple question
    How do we find the latest updated or the latest inserted record in a table ?
    Provide some queries in SQL?

    You can order by rowid desc to get lately inserted records, but I'm not sure about updated records.That is incorrect, Oracle might use old rowid's even in inserts and you cannot assure that the max(rowid) refers to the latest record.
    If the table is created with rowdependencies one can use ORA_ROWSCN pseudo column to check on date/time when the last dml has been performed over that table. But, that has some limitations too, Old snapshots will be erased hence one can check the last dml with a time frame of few days.
    Regards,
    Prazy

  • Displayin message and fixing the number of rows in a table

    Hi Experts,
    I have a requirement like this
    there is a table, where i need to diplay a message when there are no records and no rows should be visible on that table.
    Also, when the records are populated from the context, i need to fix the number of rows in that table and display the records.
    Please let me know hw this can be achieved.
    Also in the table I have Link to URL, please let me know how to handle this reference, when i set the reference Property, its giving me an error stating that the file doesn't exist when the table gets loaded.
    Thanks in Advance
    Regards,
    Palani

    Hi
    Oh!!  You should to  explain it at first thread itself that you want to display a JPG imange or other WDWebResourceTypetaken form the backend.
    1. So this is not at all a URL
    2. You have to convert binary data to WDWebResource then display it in either Image UI element or other (like PDF , txt etc)
    3
    try
                   //        Read the datasource of the FileUpload
                   IWDResource res = wdContext.currentContextElement().getResource();
                   InputStream in = res.read(false);
                   ByteArrayOutputStream bOut = new ByteArrayOutputStream();
                   int length;
                   byte[] part = new byte[10 * 1024];
                   while ((length = in.read(part)) != -1)
                        bOut.write(part, 0, length);
                   in.close();
                   bOut.close();
                   IPrivateUploadCompView.IImageTableElement ele = wdContext.nodeImageTable().createImageTableElement();
                   ele.setImage(wdContext.currentContextElement().getResource().getUrl(0));
                   ele.setText(res.getResourceName());
                   wdContext.nodeImageTable().addElement(ele);
              catch (Exception e)
                   wdComponentAPI.getMessageManager().reportWarning(e.toString());
    Here I assume that you convert that data to IWDResource type or
    4.
    WDWebResource.getWebResource(wdContext.currentContextElement().getresource(), type);
    // getResource of type binary which u read from BAPI and set it in local context , type is MIMETYPE or hardcode it as "JPG"
    5. Further help
       [Help1|To Displayan Image in Webdynpro Java from Standard Function Module;
    [Help2|http://wiki.sdn.sap.com/wiki/display/KMC/GettinganimagefromKMDocumentstobeusedinWeb+Dynpro]
    [Help3|http://wiki.sdn.sap.com/wiki/display/KMC/GettinganimagefromKMDocumenttobeusedinWeb+DynPro]
    It might code look strange at first , please do some reserch in SDN ,I did my best at this level.
    Best Regards
    Satish Kumar

  • To change the height of row of a table

    hi Experts,
    1) Can any one please help me to change the height of row of a table
    2) If i need to display data intable in such a way that data would be displayed in every alternate row, keeping one row empty.
    Points wil be rewarded to helpful answers,
    Regards,
    Sanjyoti.

    hi Jarrod, 
    i want to make a display iview where the data comes from a table, add image beside each data from the table,
    1) if i display data in table i am not able to add image beside each row.
    2)i have also tried using one form and one table displayed side by side where the table has data from data service and form has the images (static), but here again as the height of row can not be changed the image does not fit perfectly beside the rows.
    I have not worked in VC before, so dont know wat exactly cant be done,
    hope you will guide if you have any idea wat could be done
    I got the help given below but not able to understand the flow of what is done 
    First create a button to trigger an action (let's say the action is called "go").
    Drag a line and create a signal out set go as the event, name the signal out as "sig".
    Create 4 numeric fields in the signal out "num1",..,"num4".
    Map num1 <- 1
    Add a signal in to the model, name it "sig" and create 4 numeric field to it ("num1",..,"num4" as well).
    Drag a line from the signal in and choose a form from the context menu.
    4 recordsl will appear in the form. set them as visible and as spinner control.
    drag a line from the form's out port and add a signal out named "go".
    Map is as follows:
    num1 <= @num1+1
    num2 <= 1
    num3 <= if(@num2==1,1,0)
    num4 <= if@num3==1,1,0)
    Add a gaurd condition to the line @num1<4 and name the event "Next_Event"
    double click on num1 to open the properties popup.
    For num1 define a custom action named "Next_Event"
    For num2 define a custom action named "Pass1"
    For num3 define a system action move row - move next
    For num4 define a custom action named "pass2"
    drag a line from the form and add data store. Create 2 field in it "first" and "second"
    set the event to be pass1 and map the value you want from the table to "first".
    Create another line from the form to the data store with event pass 2 that maps value to second.
    Create a new form with 2 field which default vlaue is the value in the data store.
    Points would be awarded to helpful answers. 
    Regards,
    Sanjyoti.

  • Always fill out the very last row of a table (which can expand)

    Hi, I'm having problems with a button in table A that adds a row to another table (table B) and then automatically fills out some of the table row data (table A) into the newly created row of the other table (table B)
    Here's my code (on click of button in a row of Table A) - I should also mention that Table A has a button to add more rows to itself:
    This almost works - however, it only works if the amount of rows in each table match - which they don't necessarily as the user may or may not opt to add the row from table A to table B. eg. Table A could be 4 rows deep, but table B may only contain 2 Rows.
    tableB.row.addInstance(0);
    var vCol1 = this.resolveNodes("tableA.row.cellA");
    var vCol2 = this.resolveNodes("tableB.row.cellA");
    var vCol3 = this.resolveNodes("tableA.row.cellB");
    var vCol4 = this.resolveNodes("tableB.row.cellB");
    for (var i = 0; i < vCol1.length; i ++) {
                 vCol2.item(i).rawValue = vCol1.item(i).rawValue;
                 vCol4.item(i).rawValue = vCol3.item(i).rawValue;
    I'm new to scripting (learning on the fly) so my question is, seeing that the first command is to add a new row to table B, can I alter the code so that var vCol2 and vCol4 always relate to the very latest row that has been created? In that way, any previous rows that have been added will shunt down the list and will not be affected but the new button click? Or is there a better way of doing this.

    Hi,
    I think the key here is that the addInstance method returns the row it has just added.  So your add can be something like;
    var button = xfa.host.messageBox("You are about to ADD this entry to Table B. Do you wish to proceed?", "Add to Table B Section", 1, 2);
    if (button == 4)
       var newRow = tableB._tableBrow.addInstance(0);
       newRow.cellA.rawValue = cellA.rawValue;
       newRow.cellB.rawValue = cellB.rawValue;
    I'm not sure how you want the table A remove button to work?  Should it remove the first table B row with a matching cellA and cellB?
    Regards
    Bruce

  • Updating all the changed data from Vo based table into database

    hi,
    there is a advanced table in my page and there r 14columns in it. the data for this columns is coming from 8 different tables. here the table is VO(sql query) based table.there is also a apply button on the page. when i click "apply" which is submit button, i want all the changes made on the advanced table to be captured and get updated on the respective columns in the database..
    can anyone helpme out in doing this.
    Thanks
    Chandu

    SQL query based VO is not updatable. You have to base your ViewObject for all EntityObjects which represent your 8 different tables.
    Its good practice to base all your VO on EO, even for read-only, unless your query does not contain, distinct, union & group by clause.
    Setting "updatable=false" property of EO make behavior of read-only.
    Is your VO based on EO?
    See this- http://howtolearnadf.blogspot.com/2012/04/how-to-create-oracle-adf-view-object.html
    http://weblog.singhpora.com/2010/02/read-only-view-object-also-be-based-on.html

  • Need Query to that generate count of rows of all tables

    Hi
    i need a query which gives the result of no.of rows in talbe and coresponding table name.
    And then i need to compare the same with other DB schema
    Thanks in advance

    Hi User,
    We can also get the count of rows for all the tables associated with a User, we can create a custom function which
    uses the table name to return results.
      CREATE OR REPLACE FUNCTION TAB_ROWS_CNT (TAB_NAME IN VARCHAR2)
       RETURN NUMBER
    AS
       TAB_CNT   NUMBER :=0;
    BEGIN
       EXECUTE IMMEDIATE 'select count(*) from ' || TAB_NAME
          INTO TAB_CNT;
       RETURN TAB_CNT;
    END;And query,
    SELECT TABLE_NAME, TAB_ROWS_CNT (TABLE_NAME) ROW_CNT
      FROM USER_TABLES;Which gets us the count of Individual Tables for a user.
    This is an just that we can do in this way also. But, use which is optimal.
    Thanks,
    Shankar

  • How to check the number of rows in a table with input data?`

    Dear all,
    I am having a table ( with declaration of 5 rows during the init ) there's a next button which will add another 5 rows by pressing. Let say the user ony key in 7 rows of data.. how should i track it? coz these data act as input to my bapi function. One of the input field of my bapi is to state how many rows of data that a user had key in. Thank you.

    I think ur problem is empty records, u dont want to process empty table rows.
    m I right?
    if yes then just before processing the data / records, check for empty records and remove unwanted rows from the node.
    for (int i = 0; i < TableNode.size(); i++)
             if all cells of row(i) are empty
                   remove row(i) from Table Node.
    OR if you dont want to remove empty rows from display (screen), then at the time of processing, transfer useful rows to a separate node and process that node.
    Best Regards
    Deepak

  • Get the count of rows in a table control

    Hi Experts,
      How do I get the count of the rows in a table control during run time.
    I am developing a BDC in which I have to check all entries in a table control.
    My requirement is to get the total number of rows in a table control dynamically.
    Thanks
    Kumar

    Hi,
    Use a variable when u r passing the records from the internal table to the screen fields
    and display the same.
    I think this idea may help u.
    And pls explain me ur requirement clearly.
    Refer to the following link this may help u.
    http://sapabapnotes.blogspot.com/2008/03/working-with-ecatt-extended-computer.html
    Reward if helpful.
    Jagadish

  • How to change the number displaying rows in a table

    Hi all,
    i have a table for resources in Debrief Work order (Standard Screen), we need to change the default displaying rows. inistially it displayed 3 empty rows.
    i tried to change the Records Displayed for the table but it did not affect.
    also it is possible to change the "Add 3 rows" button in the table to add for example 5 rows instead?
    any idea?
    Regards,
    Mahdi Charara

    Hi,
    Through personalization we can do.On standared page top right u will find personalization link.click on the clink next expand all there find apporiate table .Here u will fine reorder button set as u want display and save. then u can see the change.For add row functionality u need to extend the co.

  • Query for how to display unique rows in a table

    Can i have a query for displaying unique rows in a table.

    use d query
    select distinct col1,col2... from table ;

  • Query to find the  second maximum date in a table

    please give me the query to find the second maximum date in a table

    You can try with this
    SELECT empno
          ,hiredate
      FROM emp        a
    WHERE 2          = (SELECT COUNT(DISTINCT hiredate)
                           FROM emp        b
                          WHERE b.hiredate      >= a.hiredate
    OR
    SELECT empno
          ,hiredate
      FROM (SELECT ROWNUM      row_num
                  ,empno
                  ,hiredate
              FROM emp        a
          ORDER BY hiredate   ASC
    WHERE row_num             = 2;Regards
    Arun

  • Count the number of rows in each table

    I have a list of table names, how to I write a query to find out the row count of each table.
    select table_name from all_tables a where owner='XXX' and num_row > 100
    or
    select table_name from all_tables a where owner='XXX' and sample_size > 100
    doesn't quite work.
    Why?
    Thanks in advance,
    Edited by: mpt_fz on Jan 12, 2010 12:06 PM

    Well, then another method learned from Michael ;)
    scott@ORCL>
    scott@ORCL>select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
    PL/SQL Release 11.1.0.6.0 - Production
    CORE    11.1.0.6.0      Production
    TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
    NLSRTL Version 11.1.0.6.0 - Production
    Elapsed: 00:00:00.14
    scott@ORCL>
    scott@ORCL>
    scott@ORCL>select table_name,
      2         DBMS_XMLGEN.getxmltype(
      3                                 'select count(*) c from '||table_name
      4                               ).extract('//text()').getnumberval() tot_rows
      5  from user_tables
      6  where iot_type is null
      7  or iot_type != 'IOT_OVERFLOW';
    TABLE_NAME                       TOT_ROWS
    A_TEST_TB_CASHFLOW                     14
    TEST_DUMMY                              1
    A_TEST_TB_CASHFLOW_N                    1
    TEST_CAST                               1
    DEPT                                    4
    EMP                                    14
    BONUS                                   0
    SALGRADE                                5
    EMP_DETAILS                             3
    T_EMP                                   0
    AUDIT_T                                 0
    TABLE_NAME                       TOT_ROWS
    C_C                                     4
    TRAIN_DET                               2
    TEST_COM_IMP                            2
    TIME_P                                  1
    PRI_UQ                                  4
    TEST_CHK                                0
    ANSHUMANSAHAISGENIOUS                   1
    T                                       1
    XEUROPE                                 2
    D_D                                     8
    PUBLICTRANSPORT                         4
    TABLE_NAME                       TOT_ROWS
    XASIA                                   2
    TF1                                     0
    TEST_HH                                14
    TEST_SWAP                               4
    REVIVE_XML                              3
    XGMT                                    1
    CUSTOMER_DET                            1
    FOURWHEELER                             2
    SPOOL_LOG                              13
    CITYTRANSPORT                           8
    T1                                      2
    TABLE_NAME                       TOT_ROWS
    T2                                      2
    A_A                                     1
    B_B                                     2
    AUTOMOBILE                              1
    XDUAL                                   1
    S_TEMP                                  0
    39 rows selected.
    Elapsed: 00:00:08.78
    scott@ORCL>Regards.
    Satyaki De.

  • Query to get the last added record in a table for a particular id

    T
    Hi,
    I have 2 tables A, B
    Table A has id,name
    Table B had parentid(foreignkey referring to ID in above table), record_type,created_timestamp
    I want to get the last added record_type from Table B for all the ids present in Table A.

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. I know this is
    a skeleton, but could you at least try to do good programming? Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. And sample data also helps. 
    I have 2 tables: Alphas, Betas
    CREATE TABLE Alphas
    (alpha_id CHAR(10) NOT NULL PRIMARY KEY,
     alpha_name VARCHAR(25) NOT NULL);
    Why was that DDL so hard you could not write it? But your narrative about the second table does not tell us if it has a key. I will guess that it is also alpha_id, but thanks to your rudeness, that is all we can do. 
    CREATE TABLE Beta 
    (alpha_id CHAR(10) NOT NULL PRIMARY KEY
       REFERENCES Alphas (alpha_id),
     record_type CHAR(2) NOT NULL,
     creation_timestamp DATETIME2(0) DEFAULT CURRENT_TIMESTAMP
          NOT NULL,
    >> I want to get the last added record_type from Table Beta for all the ids present in Table A.<<
    Think about this. Since Beta.alpha_id is a FOREIGN KEY to Alphas, all of its rows will have a match to Alpha. The SQL engine does this for you! 
    SELECT *
    FROM (SELECT alpha_id, record_type, creation_date,
                  MAX(creation_date) OVER () AS creation_date_max
            FROM Betas)
    WHERE creation_date = creation_date_max;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

Maybe you are looking for

  • IPod touch suddenly fast forwarding through songs and videos + voice control screen cutting in

    Hi In the last couple of days, it has started fast forwarding through songs and videos randomly. The voice control screen is also cutting in randomly. It happens as soon as I turn it on and play my first track or video. The only other problem I have

  • HP Officejet 5610 All-in-one paper jam problem

    Please is anyone out who can heIp me. I tried to print a word document from my computer and my printer came up with the following message: Paper jam: clear jam and press ok. I have looked through the printer to see if there is any paper jammed in the

  • Loading a blob record

    Hi, In my program I must put some new record in a database. The problems come when I have to load the column of blob type. I'd want to put into that field the contents of an array of byte[ ].

  • Time Capsule; To buy or not to buy?

    OK - I have read the reviews ,but want the product. I am in need of a 802.11N wireless router AND more storage for back-up. This seems like the perfect option, but I don't want the unit to die after 18 months. I am also in the market for Apple TV, so

  • Delete Cost Element which has a posting

    Hi, How do I delete a cost element which already has a posting in it? Thanks, Teo