How to give relationship between two tables with comon column with between oprator

Hi Folks,
I am using Sql Server 2008R2. I am getting a problem to establish relationship between two tables. 
I have two Tables, 1.Inventory Details Table another one is Inventory Header Table.
Inventory Details Table having a column Card No and inventory Header Table having columns  From card No and To Card No.
I want to give relationship between these two tables with Card no. Could you please provide me the Sql Query.
Your help would be greatly appreciated .
Regards
hasthi.
email:[email protected]

Hi Raju,
 We have two way that we can relate to the table either join or quality condition use following syntax/Query  for relating two tables 
select * from Inventory_Details ID inner join  Inventory_Header IH on ID.CardNo between IH.FrmCardno and IH.ToCardNo
or 
Select * from  Inventory_Details ID ,Inventory_Header IH where ID.CardNo=IH.CardNo OrSelect * from  Inventory_Details ID ,Inventory_Header IH where ID.CardNo between IH.FrmCardno and IH.ToCardNo
Hope this will help you 
Niraj Sevalkar

Similar Messages

  • How to get relationship between two  views in the  reports

    How to get relationship between two  views in the  reports, I am doing a deletion program , it is fully relates to views , how to get relationship between them in the reports

    Hi,
    Please explain your question in detail...what do you want to read ?
    If you want to know about the navigation links between the views then you can use APIs  like
    wdComponentAPI.getComponentInfo().findInWindows("windowName").getViewUsageByID("Name").getNavigationLinks();
    Iterate through the navigationLinkInfo from above collection and can read the other properties .
    I haven't tried the above , but it should work !!!
    Regards,Anilkumar

  • How to match columns of two tables with

    Hello:
    I've two tables like below:
    Table1:(Base Table)
    Country|Prefix|Prefix_Length
    CountryA|001|3
    CountryB|0012|4
    CountryC|00443|5
    CountryD|0091|4
    Table2:(Detail Table)
    Population|Area|Prefix
    500|AreaA|0015921
    1000|AreaB|00122
    400|AreaC|00443743
    300|AreaD|0091333
    100|AreaA|001
    I need to match these two tables with prefix column (which length is not fixed in both tables: but it starts with 00 in both tables). Two different countries prefix can be similar up to a certain length. So, Prefix_Length can be used to determine (exactly) how long should be taken to search from Table2.
    Output:
    Country|Prefix|Area|Population
    CountryA|001|AreaA|600
    CountryB|0012|AreaB|1000
    CountryC|00443|AreaC|400
    CountryD|0091|AreaD|300
    Please help me with your valuable feedback.
    -Tanvir

    You have to explain how CountryA population is calculated:
    with base_table as (
                        select 'CountryA' country,'001' prefix,3 prefix_length from dual union all
                        select 'CountryB','0012',4 from dual union all
                        select 'CountryC','00443',5 from dual union all
                        select 'CountryD','0091',4 from dual
       detail_table as (
                        select 500 population,'AreaA' area,'0015921' prefix from dual union all
                        select 1000,'AreaB','00122' from dual union all
                        select 400,'AreaC','00443743' from dual union all
                        select 300,'AreaD','0091333' from dual union all
                        select 100,'AreaA','001' from dual
    -- end of on-the-fly data sample
    select  country,
            b.prefix,
            area,
            population
      from  base_table b,
            detail_table d
      where b.prefix = substr(d.prefix,1,prefix_length)
    COUNTRY  PREFI AREA  POPULATION
    CountryA 001   AreaA        500
    CountryA 001   AreaB       1000
    CountryA 001   AreaA        100
    CountryB 0012  AreaB       1000
    CountryC 00443 AreaC        400
    CountryD 0091  AreaD        300
    6 rows selected.
    SQL> SY.

  • How to update two tables with trigger

    Hi:
    how to update two tables with trigger ?
    I have two tables :
    (1)ASIA
    MI number;
    (2)ASIA_P
    ID number;
    When I insert a new value into the asia.MI ,I also can
    insert the same value into the asia_p.id field.
    I have write a trigger as follows but it does't work.
    create or replace trigger MI_TRG
    before insert on asia
    for each row
    declare
    seq number;
    begin
    select MI_SEQ.Nextval into seq from dual;
    :new.MI:=seq;
    insert into ASIA_PRO(MI_ID)
    values
    (seq);
    end MI_TRG;
    How to realize it ?
    thanks
    zzm

    Why do you say it does not work?

  • How to compare two rows from two table with different data

    how to compare two rows from two table with different data
    e.g.
    Table 1
    ID   DESC
    1     aaa
    2     bbb
    3     ccc
    Table 2
    ID   DESC
    1     aaa
    2     xxx
    3     ccc
    Result
    2

    Create
    table tab1(ID
    int ,DE char(10))
    Create
    table tab2(ID
    int ,DE char(10))
    Insert
    into tab1 Values
    (1,'aaa')
    Insert
    into tab1  Values
    (2,'bbb')
    Insert
    into tab1 Values(3,'ccc')
    Insert
    into tab1 Values(4,'dfe')
    Insert
    into tab2 Values
    (1,'aaa')
    Insert
    into tab2  Values
    (2,'xx')
    Insert
    into tab2 Values(3,'ccc')
    Insert
    into tab2 Values(6,'wdr')
    SELECT 
    tab1.ID,tab2.ID
    As T2 from tab1
    FULL
    join tab2 on tab1.ID
    = tab2.ID  
    WHERE
    BINARY_CHECKSUM(tab1.ID,tab1.DE)
    <> BINARY_CHECKSUM(tab2.ID,tab2.DE)
    OR tab1.ID
    IS NULL
    OR 
    tab2.ID IS
    NULL
    ID column considered as a primary Key
    Apart from different record,Above query populate missing record in both tables.
    Result Set
    ID ID 
    2  2
    4 NULL
    NULL 6
    ganeshk

  • How to insert data into two tables linke with foreign key..

    I have two tables
    1)EMP(emp_ID,username,emp_type_code)
    emp_ID is primary key, emp_type_code is a foreign key references emptype table.
    2)emptype(emp_type_code,emp_type_descripton)
    emp_type_code is primary key
    Could anyone help me ..how to insert data into EMP table. How to insert data into two tables linke with foreign key..

    CREATE TABLE "CATDB"."DWDIMUSER"
    "USER_ID" NUMBER(10,0) NOT NULL ENABLE,
    "SPECIALTY_ID" NUMBER(10,0),
    "FULLNAME" VARCHAR2(20 BYTE),
    "FNAME" VARCHAR2(20 BYTE),
    "LNAME" VARCHAR2(20 BYTE),
    "USER_SUBTYPE" VARCHAR2(20 BYTE),
    CONSTRAINT "DIMUSER_PK" PRIMARY KEY ("USER_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE,
    CONSTRAINT "DIMUSER_DIMSPECIALTY_FK" FOREIGN KEY ("SPECIALTY_ID") REFERENCES "CATDB"."DWDIMSPECIALTY" ("SPECIALTY_ID") DISABLE
    CREATE TABLE "CATDB"."DIMSPECIALTY"
    "SPECIALTY_ID" NUMBER(10,0) NOT NULL ENABLE,
    "SPECIALTY_NAME" VARCHAR2(100 BYTE),
    CONSTRAINT "DIMSPECIALTY_PK" PRIMARY KEY ("SPECIALTY_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE
    INSERT INTO DIMUSER (FullName, FNAME, LNAME, USER_TYPE, USER_SUBTYPE)
    SELECT DISTINCT
    Engineer AS FullName,
    regexp_substr(Engineer , '[^,| ]+', 1, 1) as FName,
    regexp_substr(Engineer , '[^,| ]+', 1, 2) as LName ,
    'Engineer'
    FROM EMPLOYEELOOKUP;
    INSERT INTO DIMSPECIALTY (SPECIALTY_NAME)
    SELECT DISTINCT SPECIALITY
    FROM EMPLOYEELOOKUP;
    COMMIT;
    CREATE TABLE employeelookup ...IS A TABLE THAT HAS ALL THE DATA NEDED TO BE FILLED IN BOTHE TABLES...
    CREATE TABLE "CATDB"."EMPLOYEELOOKUP"
    "EMPLOYEELOOKUP_ID" NUMBER(10,0) NOT NULL ENABLE,
    "ENGINEER" VARCHAR2(25 BYTE),
    "SPECIALTY" VARCHAR2(20 BYTE),
    CONSTRAINT "DIMSPECIALTY_PK" PRIMARY KEY ("EMPLOYEELOOKUP_ID") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "CATDB" ENABLE
    DATA IN EMPLOYEELOOKUP
    Engineer, Specialty,
    John, Dow, Electronis,
    Dow, Jons, Technician
    Stan Smithers Sales
    Mark, Richards Marketing
    Jenny, Lane Marketing
    John, Lee Sales
    I NEED TO LOAD THE FOREIGN KEY IN DIMUSER FROM THE DIMSPECIALTY TABLE?
    BY USING THE LOOKUP TABLE TO MARCH THE NAMES UNDER THE Engineer COLUMN, SPECIALTY COLUMNE DISTICTIVLY BY JOINING THE DIMSPECILTY TO RISTIVE THE PRIMARY KEY AND FILL IT IN THE DIMUSER TABLE AS A FOREIGNE KEY.

  • Cartesian of data from two tables with no matching columns

    Hello,
    I was wondering – what’s the best way to create a Cartesian of data from two tables with no matching columns in such a way, so that there will be only a single SQL query generated?
    I am thinking about something like:
    for $COUNTRY in ns0: COUNTRY ()
    for $PROD in ns1:PROD()
    return <Results>
         <COUNTRY> {fn:data($COUNTRY/COUNTRY_NAME)} </COUNTRY>
         <PROD> {fn:data($PROD/PROD_NAME)} </PROD>
    </Results>
    And the expected result is combination of all COUNTRY_NAMEs with all PROD_NAMEs.
    What I’ve noticed when checking query plan is that DSP will execute two queries to have the results – one for COUNTRY_NAME and another one for PROD_NAME. Which in general results in not the best performance ;-)
    What I’ve noticed also is that when I add something like:
    where COUNTRY_NAME != PROD_NAME
    everything is ok and there is only one query created (it's red in the Query plan, but still it's ok from my pov). Still it looks to me more like a workaround, not a real best approach. I may be wrong though...
    So the question is – what’s the suggested approach for such queries?
    Thanks,
    Leszek
    Edited by xnts at 11/19/2007 10:54 AM

    Which in general results in not the best performanceI disagree. Only for two tables with very few rows, would a single sql statement give better performance.
    Suppose there are 10,000 rows in each table - the cross-product will result in 100 million rows. Sounds like a bad idea. For this reason, DSP will not push a cross-product to a database. It will get the rows from each table in separate sql statements (retrieving only 20,000 rows) and then produce the cross-product itself.
    If you want to execute sql with cross-products, you can create a sql-statement based dataservice. I recommend against doing so.

  • How can I set up two iPhones with the same contact, photos, music etc... but a different sim card and phone number. They will both be my phones, but one will be for use in other countries.

    How can I set up two iPhones with the same contact, photos, music etc... but a different sim card and phone number. They will both be my phones, but one will be for use in other countries.

    Phone A = phone with information you want duplicated
    Phone B = phone that you want to copy from A
    Backup Phone A.
    Wipe Phone B using these instructions. What to do before selling or giving away your iPhone, iPad, or iPod touch - Apple Support
    Phone B should be on the 'Hello' screen. Do not swipe it. Launch iTunes. Plug in Phone B.
    When iTunes asks if you want to set up as new phone or restore from backup, choose restore from backup of Phone A.
    After this setup, any changes to one phone (i.e. adding a contact, downloading an app) will have to be manually duplicated on the second phone, if that is your desire). Making changes to one phone will not affect the other after setup.

  • How can I load data into table with SQL*LOADER

    how can I load data into table with SQL*LOADER
    when column data length more than 255 bytes?
    when column exceed 255 ,data can not be insert into table by SQL*LOADER
    CREATE TABLE A (
    A VARCHAR2 ( 10 ) ,
    B VARCHAR2 ( 10 ) ,
    C VARCHAR2 ( 10 ) ,
    E VARCHAR2 ( 2000 ) );
    control file:
    load data
    append into table A
    fields terminated by X'09'
    (A , B , C , E )
    SQL*LOADER command:
    sqlldr test/test control=A_ctl.txt data=A.xls log=b.log
    datafile:
    column E is more than 255bytes
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)
    1     1     1     1234567------(more than 255bytes)

    Check this out.
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch06.htm#1006961

  • How to give connection between sap R/3 to sap BI 7.0 system

    how to give connection between sap R/3 to sap BI 7.0 system

    Hello,
    Check this links:
    http://help.sap.com/bp_biv135/BBLibrary/documentation/B84_BB_ConfigGuide_EN_DE.doc
    You can look at:
    OSS Note 184971 'Notes on BW source system connections' and http://help.sap.com/saphelp_nw04/helpdata/en/80/1a61e5e07211d2acb80000e829fbfe/content.htm
    You can use this best practice connectivity guide for connecting BW to any SAP source system . It explains step by step procedure to connect the source systems to BW.
    http://help.sap.com/bp_biv135/BBLibrary/documentation/B84_BB_ConfigGuide_EN_DE.doc
    http://help.sap.com/saphelp_nw2004s/helpdata/en/ac/4a4e38493e4774e10000009b38f889/frameset.htm
    http://help.sap.com/bestpractices/crossindustry/businessintelligence/v131/BBLibrary/documentation/B84_BB_ConfigGuide_EN_DE.doc
    check this:
    http://wiki.ittoolbox.com//index.php/HOWTO%3ARe%2DConnect%5FR/3%5Fand%5FBW#Type_Transaction_SM59._Maintain_RFC_destinations
    Regards,
    Jorge Diogo

  • MATERIALIZED view on two tables with Fast Refresh

    i Wanted to create MV on two tables with Fast refresh on commit.
    I followed below steps
    create materialized view log on t1 WITH PRIMARY KEY, rowid;
    create materialized view log on t2 WITH PRIMARY KEY, rowid;
    CREATE MATERIALIZED VIEW ETL_ENTITY_DIVISION_ASSO_MV
    REFRESH fast ON commit
    ENABLE QUERY REWRITE
    AS
    select A.ROWID B.ROWID,a.c1, DECODE(a.c1,'aaa','xxx','aaa') c2
    from t1 A
    join t2 b
    on AB.c1= CD.c2;
    i am getting below error.
    Error report:
    SQL Error: ORA-12054: cannot set the ON COMMIT refresh attribute for the materialized view
    12054. 00000 - "cannot set the ON COMMIT refresh attribute for the materialized view"
    *Cause:    The materialized view did not satisfy conditions for refresh at
    commit time.
    *Action:   Specify only valid options.
    Basically i want to take record in MV by joinig two tables and if both of the base tables will updated then record should reflect in materialised view.
    Please do the needfull.

    does the table support PCT? the other restrictions on joins look to be ok in your statement.
    maybe try creating first with on demand instead of commit to see does it create.
    http://docs.oracle.com/cd/B19306_01/server.102/b14223/basicmv.htm
    >
    Materialized Views Containing Only Joins
    Some materialized views contain only joins and no aggregates, such as in Example 8-4, where a materialized view is created that joins the sales table to the times and customers tables. The advantage of creating this type of materialized view is that expensive joins will be precalculated.
    Fast refresh for a materialized view containing only joins is possible after any type of DML to the base tables (direct-path or conventional INSERT, UPDATE, or DELETE).
    A materialized view containing only joins can be defined to be refreshed ON COMMIT or ON DEMAND. If it is ON COMMIT, the refresh is performed at commit time of the transaction that does DML on the materialized view's detail table.
    If you specify REFRESH FAST, Oracle performs further verification of the query definition to ensure that fast refresh can be performed if any of the detail tables change. These additional checks are:
    A materialized view log must be present for each detail table unless the table supports PCT. Also, when a materialized view log is required, the ROWID column must be present in each materialized view log.
    The rowids of all the detail tables must appear in the SELECT list of the materialized view query definition.
    If some of these restrictions are not met, you can create the materialized view as REFRESH FORCE to take advantage of fast refresh when it is possible. If one of the tables did not meet all of the criteria, but the other tables did, the materialized view would still be fast refreshable with respect to the other tables for which all the criteria are met.

  • How do you delete records from table with data in a select option

    how do you delete records from table with relevant to data in a select option..how to write coding

    Hi,
    Try
    if not s_select_option [ ] is initial.
    delete * from table
    where field in s_select_option.
    endif.
    commit work.
    Be careful though. If select option is emty, you will delete the entire table.
    Regards,
    Arek

  • How can I write into a table cell (row, column are given) in a databae?

    How can I write into a table cell (row, column are given) in a database using LabVIEW Database Toolkit? I am using Ms Access. Suppose I have three columns in a table, I write 1st row of 1st column, then 1st row of 3rd column. The problem I am having is after writing the 1st row 1st column, the reference goes to second row and if I write into 3rd column, it goes to 2nd row 3rd column. Any suggestion? 
    Solved!
    Go to Solution.

    When you do a SQL INSERT command, you create a new row. If you want to change an existing row, you have to use the UPDATE command (i.e. UPDATE tablename SET column = value WHERE some_column=some_value). The some_column could be the unique ID of each row, a date/time, etc.
    I have no idea what function to use in the toolkit to execute a SQL command since I don't use the toolkit. I also don't understand why you just don't do a single INSERT. It would be much faster.

  • How to join two tables with no similar columns

    Hi all,
    I have two tables as follows:
    Table T1 have Attributes as follows:
    GLCODE,
    BRANCH,
    ITEM_NUMBER,
    DEMAND_DATE,
    QUANTITY,
    SOURCE
    Table T2 have Attributes as follows:
    FORECAST_DATE
    Now in SQL if run the following stattement iam getting out put.
    SELECT GLCODE,BRANCH,ITEM_NUMBER,DEMAND_DATE,QUANTITY, SOURCE,(SELECT DISTINCT FORECAST_DATE FROM T2) FROM T1
    The above SQL Statement giving correct results for me.
    The same SQL Statement how can we implement in mapping level?
    Regards,
    Ava

    Jaap van,
    >
    You have to specify an outer join, but how do you do that if there is no join to begin with? I would do the following (which I didn't test yet):
    add an extra column (say C_JOIN) to the T2-ingroup of the join operator and fill it with from a constant operator with say value 1. Then use T2.C_JOIN (+) = 1 as the join condition.
    If every record in T2 is guaranteed to have the same value, instead of using a deduplicator, which will read all records, sort them and deduplicate them, you can use a filter with filter condition ROWNUM < 2, which only will read one record.
    I am facing almost the same problem but not entirely thou and I was wondering if you have an idea how to even start.
    Problem:
    I got this table:SQL> desc ita.tpis32_job_status
    Name Null? Type
    JOBID NOT NULL NUMBER
    T1_ID NUMBER
    QID NUMBER
    REQ_TYPE VARCHAR2(10)
    SUBMIT_TIME DATE
    OWNERID VARCHAR2(30)
    DESCRIPTION VARCHAR2(150)
    STARTTIME DATE
    ENDTIME DATE
    STATUS VARCHAR2(50)
    ERROR_ID NUMBER
    TABLE_NAME VARCHAR2(30)
    SERVER_ID VARCHAR2(10)
    DATABASE VARCHAR2(20)
    PRIORITY NUMBER
    NUM_LINES NUMBER
    PROCESS_ID NUMBER
    QUE_TIME NUMBER
    STATUS_CODE NUMBER
    ERROR_MSG VARCHAR2(500)
    NUM_LINES_TS NUMBER
    REMOTE_STATUS NUMBER
    This the above table, i am looking for JOBID (a five digit number) like 25875.
    What I want to do is add or append this five digit number to a string to find the corresponding table in dba_tables or all_tables. The only way I have try to do this is by writing PLSQL as you see from here:
    Re: Use PLSQL to delete tables dynamically
    When the select is writing properly, the result of the five digit number from JOBID and the string should look like the below result (job_(five digit_%).
    My problem is there is no relationship between ALL_TABLES and the my own table (ita.tpis32_job_status). Any help will be appreciated.
    TABLE_NAME
    JOB_58871_OUTDATA
    JOB_58868_TS
    JOB_58868_OUTDATA
    JOB_58867_TS
    JOB_58867_CMDLBL_2
    JOB_58867_OUTDATA
    JOB_58866_TS

  • How to use common object from two tables with out join.

    HI,
    I have two tables called A & B In A table i have the following objects
    1.weekend
    2.S1(measure)
    3.S2(measure)
    4.S3(measure)
    5.S4(measure)
    And In B table i have followning columns
    1.week end
    2.p1(measure)
    3.p2(measure)
    4.p3(measure)
    5.p4(measure)
    Now in universe i created all the measure objects i.e.s1,s2,s3,s4,p1,p2,p3,p4 A.weekend,B.weekend.
    instead of using week end two times i wnt to use only once because this is common in both table.
    if i use join between these tables i am getting values fine
    But With out join is there any thing to do in universe level to create common objects to use from both the tables..I tried using aggregate awareness but while reporting it is taking as two SQL.which is not synchronized.
    Please help me on this ...

    hi,
    Although  Weekend column is present in both tables, by creating a single Object in Universe, Universe can identify relationship with only table referenced in Object Creation.
    So, there will be no identification of relationship with other table measures.
    Obviously, you need to create 2 Weekend objects in Universe (in two classes).
    Case 1: You need not join these two tables in Universe. When you create 2 Queries in WEBI, automatcially Weekend objects are synchronized (if both are of same datatype)
    Case 2: If you join these two tables in Universe, Obviously,
    your SQL may contain Weekend from Table1, measures from Table 2
    or
    your SQL may contain Weekend from Table2, measures from Table 1
    Finally, You need to create 2 objects in Universe. But your query may contain a single Object based on Case 2.
    Regards,
    Vamsee

Maybe you are looking for