Create a variable in one table based on a value on another.

I have two existing tables, say TABLE1 and TABLE2.  I need to create a key variable in TABLE2 and insert values for that  variable from TABLE1 i.e. create an explicit relationship between the tables using a key variable.  There exists a relationship
between the tables in that for each record in TABLE1 there are 28 records in TABLE2 and the records are arranged in sequential order. So:
TABLE1 TABLE2
REQUIREMENT
RECORD 1 -->
RECORDS 1 to 28 Copy key variable from RECORD1 in TABLE1 into RECORDS 1 to 28 in TABLE2
RECORD 2 -->
RECORDS 29 to 56 Copy key variable from RECORD2 in TABLE1 into RECORDS 29 to 56 in TABLE2
RECORD 3 -->
RECORDS 57 to 84 Copy key variable from RECORD3 in TABLE1 into RECORDS 57 to 84 in TABLE2
RECORD n--> RECORDS (n-1) * 28 + 1 to n * 28
Copy key variable from RECORD n in TABLE1 into RECORDS (n-1) * 28 + 1 to RECORDS n * 28 in TABLE2
Please help if you can.  I am prepared to give any additional information when asked.

TABLE1:
USE [LFS_APRIL_2015]
GO
/****** Object:  Table [dbo].[HOUSING37854]    Script Date: 04/30/2015 15:52:37 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[HOUSING37854](
[BatchNo] [float] NULL,
[District] [float] NULL,
[URBAN_RURAL] [float] NULL,
[HHNUM] [float] NULL,
[Cluster] [float] NULL,
[Final_Result_Code] [float] NULL,
[zBarcode] [float] NULL,
[Person_NUMBER] [float] NULL,
[HH1] [float] NULL,
[HH2] [float] NULL,
[HH6] [float] NULL,
[HH4] [float] NULL,
[HH3] [float] NULL,
[HH5] [float] NULL,
[HH7] [float] NULL,
[HH8] [float] NULL,
[HH9a] [float] NULL,
[HH9b] [float] NULL,
[HH9c] [float] NULL,
[HH9d] [float] NULL,
[HH9e] [float] NULL,
[HH9f] [float] NULL,
[HH9g] [float] NULL,
[HH9h] [float] NULL,
[HH9i] [float] NULL,
[HH9j] [float] NULL,
[HH9k] [float] NULL,
[HH9l] [float] NULL,
[HH9m] [float] NULL,
[HH10a] [varchar](1) NULL,
[HH10b] [varchar](1) NULL,
[HH10c] [varchar](1) NULL,
[ED_Number] [float] NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
TABLE2:
USE [LFS_APRIL_2015]
GO
/****** Object:  Table [dbo].[LISTING37854]    Script Date: 04/30/2015 15:47:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[LISTING37854](
[HL1] [float] NULL,
[HL3] [float] NULL,
[HL4] [float] NULL,
[HL5] [float] NULL,
[HL6] [float] NULL,
[HL7] [float] NULL
) ON [PRIMARY]
GO
Essentially The Housing table, TABLE1, lists households and the Listing table, TABLE2, lists members of the household and there are always 28 lines in the Listings although most of them may be just a number since almost no household will have 28
members.  The Listings that is jut a number will be deleted,  but to know where the listing for the next household starts I need to create the linking variable in Listings table.  The is absolutely no doubt that the relationship that I specified
in the first post above is as specified.

Similar Messages

  • Create a column on one sheet based on unique value in another

    Hello,
    I'm running Excel 2013 and I have one workbook with two sheets - sheet1 and sheet2. Sheet1 has 24 columns and 26K rows. Column "A" is titled "id" and contains
    id numbers that are also, some, found in column "A" of Sheet2 - which is also titled "id".
    Sheet1 has no "description" column. Sheet 2 only has 2 columns - "A" is the "id" column and "b" is the "description" column.
    A B
    ID Description
    58749651 a bunch of text
    How can I create a description column on sheet1 (it would be column "U") and populate it with the description from sheet2 only where the "id" values from column "A" match?
    Thanks!
    Rob

    Hi Rob,
    Utilize the VLOOKUP function and this should resolve it. 
    For example, in a new column on sheet 1 (Y) a formula like this should suffice assuming ID is in column A:
    =VLOOKUP(A1,Sheet2!A:B,2,FALSE)
    Or more elegant:
    =IFERROR(VLOOKUP(A1,Sheet2!A:B,2,FALSE),"")
    More information on VLOOKUP can be found here: VLOOKUP Function

  • Display an exception on one keyfigure based on the value of another key fig

    Hello all,
    How to run a exception based on some condition i.e
    i want to highlight the sales(key figure) which r less than the  average sales..
    where sales and average sales r keyfigures...
    i also created a cal key fig which has has value 1 if sale > avg sale...
    i.e How do i display an exception on one keyfigure depending on the value of another keyfigure??
    plz reply its urgent...
    thnx in advance...

    Hello Ajay, did you got an answer for your problem? I'm interested...
    Thx Masen
    Edited by: Masen-Fuad Marei on Nov 25, 2009 6:26 PM

  • Insert values to one table based on a value inserted into another table

    Hi,
    I've got a form based off a report which creates a new project. I've added an additional process to this form to insert four new values into another table as soon as the new project is created and the PK for that project is generated. This was working last week (of course!) and now seems to not work at all. It's complaining that the PK I was getting from my first insert was null. Here is one the the statements in my process I'm trying to run:
    insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY')) FROM dual), 0, '', :P45_PROJECT_SEQ, sysdate, :APP_USER);
    The complaint I get that it's getting null where :P45_PROJECT_SEQ should be.
    Thoughts?
    Thanks,
    Jon

    Hi Andy,
    Thanks for the tip. Those two values didn't match and I updated them so they do and I'm still getting a "cannot insert NULL..." error.
    When I turn on debug I see that I'm getting the PK and I see the value. Here's my debug output:
    0.24: ...Process "Get PK": PLSQL (AFTER_SUBMIT) declare function get_pk return varchar2 is begin for c1 in (select PROJECT_SEQ.nextval next_val from dual) loop return c1.next_val; end loop; end; begin :P45_PROJECT_SEQ := get_pk; end;
    0.25: ...Session State: Saved Item "P45_PROJECT_SEQ" New Value="252"
    0.25: ...Process "Process Row of PROJECT": DML_PROCESS_ROW (AFTER_SUBMIT) #OWNER#:PROJECT:P45_PROJECT_SEQ:PROJECT_SEQ|IUD
    0.26: ...Session State: Save "P45_PROJECT_SEQ" - saving same value: "252"
    0.26: ...Process "reset page": CLEAR_CACHE_FOR_PAGES (AFTER_SUBMIT) 45
    0.27: Nulling cache for application "120" page: 45
    0.27: ...Process "Add Week Groups": PLSQL (AFTER_SUBMIT) insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY')) FROM dual), 0, '', :P45_PROJECT_SEQ, sysdate, :APP_USER); insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY') +
    0.28: Encountered unhandled exception in process type PLSQL
    0.28: Show ERROR page...
    0.28: Performing rollback...
    I notice that when it runs my process "Add Week Groups" it's not displaying all of the SQL. But the SQL is fine, it's right here:
    insert into week_group values(week_group_seq.nextval, (SELECT trunc(NEXT_DAY(SYSDATE, 'FRIDAY')) FROM dual), 0, '', :P45_PROJECT_SEQ, sysdate, :APP_USER);
    Hmmm....what about the "reset page" action in the last of the 0.26 lines?
    Thanks,
    Jon

  • Dynamic Column Names from one table and its corresponding values from another table

    I have 2 tables. First tables gives the specification if a column is required or not. we have the 2nd table with the same column name where we provide the actual values.
    I want to select all the required columns from the 1st table and retrieve the values for those from the 2nd table. Both this i want to achieve in a single select statement.

    This wil require a dynamic Query with a Pivot
    DECLARE @ColsPivot as VARCHAR(MAX);
    DECLARE @Query  AS VARCHAR(MAX);
    1. Retreive the ID for all required field
    SET @ColsPivot = (SELECT STUFF((SELECT  ',' + quotename(CAST([RequirementID] as varchar(3))) FROM [dbo].[Requirement] WHERE required=1 FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)') ,1,1,''));
    This will give you : [1],[2],[3],[8],[9],[14] for exemple.
    2. Build your Query
    SET @Query ='SELECT ClientID,'+@ColsPivot+''
        FROM (
            SELECT [ClientID],[RequirementID],[Value]
            FROM dbo.RequirementValue
            WHERE ClientID=@CliendID --Optional SP parameter
        )src
              PIVOT(
                MAX(Value)
                for [RequirementID] in ('+@ColsPivot+')
        ) p';
    3. Exec(@Query);

  • Update one table with the max value of another table

    CREATE TABLE [dbo].[General](
    [a_id] int NOT NULL,
    [a_date] datetime NOT NULL,
    [c_date] datetime NULL)
    CREATE TABLE [dbo].[Specific](
    [a_id] int NOT NULL,
    [a_date] datetime NOT NULL,
    [b_id] int NOT NULL,
    [d_date] datetime NULL)
    insert into General values (111,'Jan 1 2013', null)
    insert into General values (112,'Jan 1 2013', 'Mar 10 2014')
    insert into General values (113,'Jan 1 2013', null)
    insert into General values (114,'Feb 1 2013', null)
    insert into General values (115,'Feb 1 2013', 'Apr 1 2013')
    insert into General values (116,'Feb 1 2013', 'Jan 1 1970')
    insert into Specific values (111,'Jan 1 2013',1, 'Jan 1 2013')
    insert into Specific values (111,'Jan 1 2013',2, 'Feb 1 2013')
    insert into Specific values (111,'Jan 1 2013',3, 'Mar 1 2013')
    insert into Specific values (112,'Jan 1 2013',1, 'Jan 1 2013')
    insert into Specific values (112,'Jan 1 2013',2, 'Feb 1 2013')
    insert into Specific values (113,'Jan 1 2013',1, 'Jan 1 1970')
    insert into Specific values (114,'Feb 1 2013',1, null)
    insert into Specific values (115,'Feb 1 2013',1, 'Jan 15 2013')
    insert into Specific values (115,'Feb 1 2013',2, 'Feb 15 2013')
    insert into Specific values (116,'Feb 1 2013',1, 'Jan 30 2013')
    insert into Specific values (116,'Feb 1 2013',2, 'Jan 1 1970')
    I want to update General.c_date only when the values are null or Jan 1 1970 from the maximum value of Specific.d_date as long as the maximum is not null or Jan 1 1970.    The two tables join on a_id and a_date.  In the example  above 
    a_id = 111 and a_date = Jan 1 2013 should have c_date = Mar 1 2013 and a_id = 116 and a_date = Feb 1 2013 should have c_date = Jan 30 2013.
    lg

    Try the below:
    CREATE TABLE [dbo].[General](
    [a_id] int NOT NULL,
    [a_date] datetime NOT NULL,
    [c_date] datetime NULL)
    CREATE TABLE [dbo].[Specific](
    [a_id] int NOT NULL,
    [a_date] datetime NOT NULL,
    [b_id] int NOT NULL,
    [d_date] datetime NULL)
    insert into General values (111,'Jan 1 2013', null)
    insert into General values (112,'Jan 1 2013', 'Mar 10 2014')
    insert into General values (113,'Jan 1 2013', null)
    insert into General values (114,'Feb 1 2013', null)
    insert into General values (115,'Feb 1 2013', 'Apr 1 2013')
    insert into General values (116,'Feb 1 2013', 'Jan 1 1970')
    insert into Specific values (111,'Jan 1 2013',1, 'Jan 1 2013')
    insert into Specific values (111,'Jan 1 2013',2, 'Feb 1 2013')
    insert into Specific values (111,'Jan 1 2013',3, 'Mar 1 2013')
    insert into Specific values (112,'Jan 1 2013',1, 'Jan 1 2013')
    insert into Specific values (112,'Jan 1 2013',2, 'Feb 1 2013')
    insert into Specific values (113,'Jan 1 2013',1, 'Jan 1 1970')
    insert into Specific values (114,'Feb 1 2013',1, null)
    insert into Specific values (115,'Feb 1 2013',1, 'Jan 15 2013')
    insert into Specific values (115,'Feb 1 2013',2, 'Feb 15 2013')
    insert into Specific values (116,'Feb 1 2013',1, 'Jan 30 2013')
    insert into Specific values (116,'Feb 1 2013',2, 'Jan 1 1970')
    update A
    Set c_date = (Select MAX(d_date) From Specific B where A.a_id = B.a_id Group by a_id
    having MAX(d_date) is not null
    and MAX(d_date)<>'1970-01-01 00:00:00.000')
    From General A
    Select * From General
    Drop table general,specific
    This would cause all records in General table to get updated which is not what asker want
    see below statement
    I want to update General.c_date only when the values are null or Jan 1 1970
    from the maximum value of Specific.d_date as long as the maximum is not null or Jan 1 1970
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to modify F4 help of one parameter based on the value of another?

    Hi,
    My Query is as follows:
    I have 3 select-options / parameters on the selection screen.
    If I enter some value in the first parameter the values in the second parameter should reflect accordingly.
    For example: The 3 selection-screen parameters are:
    select-options: s_werks for pa0001-werks no intervals,
                          s_btrtl for pa0001-btrtl no intervals,
                          s_kostl for pa0001-kostl no intervals.
    On exceuting the report, say I do a F4 and select '1000' for the first parameter (s_werks).
    Now after selecting the value for the first parameter if I do a F4 on the second parameter (s_btrtl) then it should prompt me with a F4 help containing values only corresponding to '1000' entered in s_werks and not all the values maintainined for btrtl.
    I have tried AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_BTRTL-LOW.
    And then used the FM F4IF_INT_TABLE_VALUE_REQUEST.
    But At Selection-Screen On Value Request the selection screen parameter s_werks does not show any value. It reflects the value only once it reaches Start-of-selection.
    Can anyone please guide me how to go about it?

    hi
    Please do it in this way..
    TABLES: pa0001.
    select-options: s_werks for pa0001-werks no intervals,
    s_btrtl for pa0001-btrtl no intervals,
    s_kostl for pa0001-kostl no intervals.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_BTRTL-LOW.
      PERFORM sub_pop_btrtl .
    *&      Form  sub_pop_btrtl
          text
    -->  p1        text
    <--  p2        text
    form sub_pop_btrtl .
    DATA :  l_wa_dynp TYPE dynpread,
            l_i_dynp TYPE STANDARD TABLE OF dynpread,
            l_wa_temp LIKE LINE OF S_werks.
    REFRESH s_temp[].
      l_wa_dynp-fieldname = 'S_WERKS-LOW'.
      APPEND l_wa_dynp TO l_i_dynp.
    Get the screen values of template
      CALL FUNCTION 'DYNP_VALUES_READ'
        EXPORTING
          dyname               = sy-repid
          dynumb               = sy-dynnr
        TABLES
          dynpfields           = l_i_dynp
        EXCEPTIONS
          invalid_abapworkarea = 1
          invalid_dynprofield  = 2
          invalid_dynproname   = 3
          invalid_dynpronummer = 4
          invalid_request      = 5
          no_fielddescription  = 6
          invalid_parameter    = 7
          undefind_error       = 8
          double_conversion    = 9
          stepl_not_found      = 10
          OTHERS               = 11.
      IF sy-subrc <> 0.
    Do Nothing
      ENDIF.
    Put the screen value in the select-options
      READ TABLE l_i_dynp INTO l_wa_dynp INDEX 1.
      l_wa_temp-sign = 'I'.
      l_wa_temp-option = 'EQ'.
      l_wa_temp-low = l_wa_dynp-fieldvalue.
    Now you use l_wa_temp as plant field
    endform.                    " sub_pop_btrtl

  • Conditionally Formatting One Column Based On The Value of Another Column

    I have the following requirement:
    I have 2 columns in a report showing Actual Sales & Budget Sales each year. I am using a bar chart to show the different values for these 2 columns.
    I need to conditionally format the column "Actual Sales" so that if it is less than the "Budget Sales" it will appear in red, and green if "Actual Sales" is greater than "Budget Sales." So in a nutshell,
    CASE WHEN "Actual Sales" < "Budget Sales" THEN
    RED
    ELSE
    GREEN
    END
    Thoughts anyone?

    CASE WHEN (COL1 - COL2) < 0 then Red else Green end
    regards
    John
    http://obiee101.blogspot.com

  • Filter one table based on user selection

    Hi all ,
              I am creating simple employee data application in VC. It consists of roadmap. On first step user searches for employee by giving first name , last name then he searches for employee and all the data related to employee's is fetched out at one shot through BAPI_EMPLOYEE_GETDATA. Now after step one no of employee comes.
    When I select one record I want that for the selected rows employee's personal data should be fetched out from another table (which is populated during first BAPI call). so I want to pass the selected key value and filter that table based on passed value to table and filter the table .
    Kindly give a solution as to implement filter on a table without making another BAPI call .
    Thanks in advance
    Abhay

    Hi Abhay,
    There's a trick to get a 'dynamic' filter (i.e. a filter that filters on a value that can change) out of the normal static filters:
    Just click on the output of your data source, then 'configure' and on the '+'  - sign in the lower right corner. Add a boolean field called 'condition', for example. Then, you write the condition that filters out the row(s) that you need. In the filter that comes next in the dataflow you just filter on this 'condition' - field being true.
    Hope that helps,
    Sincerely,
    Florian

  • How to update one table based on another table ??

    Hello Friends:
    I am trying to run the following query in oracle but it won't run.
    UPDATE BOYS
    SET
    BOYS.AGE = GIRLS.AGE
    FROM GIRLS
    WHERE
    BOYS.FIRSTNAME = GIRLS.FIRSTNAME AND
    BOYS.LASTNAME = GIRLS.LASTNAME;
    This query runs fine in sql server but in oracle its saying can't find "SET". PLease tell me what is the correct syntax in oracle to update one table based on another table.
    thanks

    See if this helps.
    If you wrote an SQL statement:
    update boys set age = 10;
    Every row in the boys table will get updated with an age of 10. But if you wrote:
    update boys set age = 10
    where firstname = 'Joe';
    Then only the rows where the firstname is Joe would be updated with an age of 10.
    Now replace the 10 in the above statements with (select g.age from girls g where g.firstname = b.firstname and g.lastname = b.lastname) and replace where firstname = 'Joe' in the second statement with where exists (select null from girls g where g.firstname = b.firstname and g.lastname = b.lastname). The same concepts apply whether 10 is an actual value or a query and whether you have a where clause with the update statement to limit rows being updated.
    About the select null question regarding the outer where clause:
    Since the query is checking to see if the row in the girls table exists in the boys table what the column is in this select statement doesn't matter, this column isn't being used anywhere. In this case Todd chose to use null. He could have also used a column name from the table or a lot of times you'll see the literal value 1 used here.

  • Create Foreing Key to one table in different dataBase

    Hi, I need create a reference to one table in other database. I understand that Database Link can be used to connect me to other database but when I am creating the foreing key in my table, I can see only the tables in the schemas that have my data base not the other schemas. I created a connection with database link but I do not see the form to make reference to this connection from the create table wizard. I am using Oracle 9i and the client is 9.01.01.
    Thanks in advance,
    Mónica Alarcón

    We cannot use tables in another table to enforce data integrity. This makes a lot of sense if you think about what would happen if the remote database goes down.
    If you want to do this, then you need to use replication (materilaized view) to bring the parent table's data into the locaL database.
    Cheers, APC

  • Hide a column in one table view but show it in another

    I need to hide a column in one tables view but show it in another table view in the same report. Is this possible?
    Any help on this is appreciated.
    Edited by: VNC on Jan 11, 2010 9:26 AM

    Hi VNC,
    If you're crafty with javascript, you could probably write a script that would set the CSS property DISPLAY to NONE to hide the column in the table view you didn't want but leave it there in the view you did want.
    -Joe

  • Fields required based on a value in another field

    Hi,
    I am looking to have fields required (Annual Revenues and # of Employees) based on the value of another field (Ownership). Basically, if the value is Public the user is required to enter the Annual Revenue and Employees fields. I thought about using dynamic layouts but the only key field for Accounts is Account Type.
    Thanks,
    Caryn

    Hi Caryn!
    I think it is not possible for making #Employees and Revenues required depending on Ownership(as it is a look up field).. it should be possible if you want to do it on any other criteria other than ownership by just renaming the Account Type, Disable all the values of Account Tyope add new values to Pick List and make it driving picklist upon your requirements..
    If you require Account Type, create a custom picklist "Account-Type" and add the values.

  • Validating an attribute based on the value of another while inserting

    Hi guys
    I need to validate an attribute based on the value of another attribute.
    Example:
    inside some entity I have the following validation function
    public boolean validateAtt1(Number data){
         if (this.getAtt2() < some vlaue)
              return false;
         return true;
    this function works fine when I'm updating a record, but when I'm inserting a new record the this.getAtt2 return null, now I don't want to override the validateEntity function I want to override the validate function for att1; so in other words is there a way to reach att2 in the validation function of att1 when I'm inserting a new record, because the this.getAtt2() returns null if I'm inserting a new record.

    Using attribute-level setter methods won't work because when the value of a particular attribute is being set, the values of the other attributes might not yet have been set. This explains for example why it does not work when inserting a new record. You therefore have to validate at entity level.
    Rather than coding on the validateEntity() method you use a built-in Validator or Method Validator. When recording validators like this, you can provide a separate message for each business rule. If you also have the bundled exception mode enables (which will be the case by default for web applications), then multiple messages can be shown at the same time.
    If you have one business rule involving two different attributes, for example a and b, and you must provide different messages based on if a is causing the violation or b, you can do it like this:
    - implement one method doing the validation and that will indicate which attribute is causing the violation
    - implement two different method validators (with two different messages) that call the method doing the actual validation and return false based on the attribute causing the violation
    For more information about implementing business rules in ADF BC, you might have a look at this white paper:
    http://www.oracle.com/technology/products/jdev/collateral/papers/10131/businessrulesinadfbctechnicalwp.pdf
    Jan Kettenis

  • How to Visible/Hide an Item based on the value of another Item

    Hi
    I need to visible and hide a textitem based on the value of another item.This form has 3 blocks, and the both item is in the first Master Block.
    My code is:
    if :RECORDTYPE=7 then
         Set_Item_Property('BLOCK.ITEM',VISIBLE,PROPERTY_TRUE);
         Set_Item_Property('BLOCK.ITEM',ENABLED,PROPERTY_TRUE);
    ELSE
         Set_Item_Property('BLOCK.ITEM',VISIBLE,PROPERTY_FALSE);
    Set_Item_Property('BLOCK.ITEM',ENABLED,PROPERTY_FALSE);
    :BLOCK.ITEM:=NULL;
    end if;     
    I wrote the code in the Validate Trigger, but not working when moving Next Record & Previous Record
    Thanks in advance
    Rizly

    Read the 'Propagation of Property Changes' section towards the end of the page for Set_Item_Property in the online help. I'm not sure what you mean by locking automatically but perhaps it's because of this.
    You should also ensure the item you're setting to invisible is not the current item (check :system.cursor_item and go to a different item if necessary).

Maybe you are looking for