You must Sign In to post a response.
  • Category: SQL Server

    Want to join 4 tables

    hi

    i am having 4 tables. the common field is itemcode. want to join 4 tables and display some fields.i tried the query as

    CREATE TABLE #Test( itemcode nvarchar(50), itemname nvarchar(50),qty1 float,qty2 float,qty3 float,qty4 float )
    INSERT INTO #Test (itemcode, itemname,qty1,qty2,qty3,qty4)
    SELECT
    lg.itemcode,lg.descpn,lg.qty,dg.tfrqty,dag.dmg_qty,mrv.rtn_qty

    from ((tbl_lpo_res_grid as lg inner join
    tbl_delord_grid as dg on lg.itemcode=dg.itemcode) inner join
    (tbl_damage_grid as dag inner join
    tbl_mrv_rtn_grid as mrv on dag.itemcode=mrv.itemcode))

    select * from #Test

    but showing error.pls correct me
  • #762535
    Hi

    try this Query



    INSERT INTO #Test (itemcode, itemname,qty1,qty2,qty3,qty4)
    SELECT lg.itemcode,lg.descpn,lg.qty,dg.tfrqty,dag.dmg_qty,mrv.rtn_qty
    from tbl_lpo_res_grid lg inner join --- here need to your on statment
    tbl_delord_grid dg on lg.itemcode=dg.itemcode inner join
    tbl_damage_grid dag inner join --- here need to your on statment
    tbl_mrv_rtn_grid mrv on dag.itemcode=mrv.itemcode



    Can you share your all table script which is you use inner join table structure need then we can easily reply quick

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762541
    Hello.

    What error you got, you should post the error then only any one can understand your query.
    Provide the all table details with columns.

    Sridhar Thota.
    Editor: DNS Forum.

  • #762550
    Hi,

    Can you please share your error details, so that we can help you..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762607
    Hi

    To join more than two or three tables with joins like below
    select
    lg.itemcode,lg.descpn,lg.qty,dg.tfrqty,dag.dmg_qty,mrv.rtn_qty

    from tbl_lpo_res_grid as lg
    inner join
    tbl_delord_grid as dg
    on lg.itemcode=dg.itemcode
    inner join
    tbl_damage_grid as dag
    inner join
    tbl_mrv_rtn_grid as mrv
    on dag.itemcode=mrv.itemcode

    Regards

    Sai Krishna Reddy.

  • #762632
    Remove the parentheses. I guess that should solve your problem.

  • #762972
    SELECT e1.emp_id, e1.emp_name, e1.emp_pf, e2. designation_name, e3.pfacc1, e3.pfacc2, e4. pf_percent, e4.pf_max

    from emp_details e1, tbl_designation e2, tbl_empcontribution e3, tbl_empdeduction e4

    where e1.emp_id= e2.emp_id and e2.emp_id=e3.emp_id and e3.emp_id= e4.emp_id;

    Hope this helps

  • #762973

  • #763219
    Hi,

    SELECT COMMENT1,CASENUM,PROGRAMCODE,PARTICIPANTID, CLAPAYTRANNUM,PAYEENAME, CLAIMPAYEENUM, PAYMENTAMOUNT,SUBMITTEDAMOUNT,LASTNAME, FIRSTNAME,DATEPROCESSED, LEVEL1ORG, PAYEESTATE,ACTIONCODE,PYMTSTATE,TRANTYPE
    FROM CLAIMMAST INNER JOIN CLAIMTRANH ON "CLAIMMAST"."LEVEL1ORG"="CLAIMTRANH"."LEVEL1ORG" AND "CLAIMMAST"."CASENUM"="CLAIMTRANH"."CASENUM"
    INNER JOIN PARTICIPANT ON "CLAIMMAST"."LEVEL1ORG"="PARTICIPANT"."LEVEL1ORG" AND "CLAIMMAST"."PARTICIPANTID"="PARTICIPANT"."PARTICIPANTID" AND "CLAIMMAST"."PROGRAMCODE"="PARTICIPANT"."PROGRAMCODE" AND "CLAIMMAST"."GROUPCODE"="PARTICIPANT"."GROUPCODE"
    INNER JOIN CLAIMTRAN ON "CLAIMTRANH"."LEVEL1ORG"="CLAIMTRAN"."LEVEL1ORG" AND "CLAIMTRANH"."CLAPAYTRANNUM"="CLAIMTRAN"."CLAPAYTRANNUM"
    INNER JOIN CLAIMSPAYEE ON "CLAIMTRANH"."LEVEL1ORG"="CLAIMSPAYEE"."LEVEL1ORG" AND "CLAIMTRANH"."CLAIMPAYEENUM"="CLAIMSPAYEE"."CLAIMPAYEENUM"
    INNER JOIN CLAPAYTRANH ON "CLAPAYTRANH"."CASENUM"="CLAIMTRANH"."CASENUM"
    WHERE "CLAIMTRANH"."DATEPROCESSED">=TO_DATE(:FromDate,'yyyy-mm-dd HH24:mi:ss') AND "CLAIMTRANH"."DATEPROCESSED">=TO_DATE(:FromDate,'yyyy-mm-dd HH24:mi:ss') AND "CLAIMTRANH"."PAYEESTATE"='MA' OR "CLAIMTRAN"."ACTIONCODE"='002' OR "CLAIMSPAYEE"."PYMTSTATE"='MA' AND "CLAIMTRANH"."LEVEL1ORG"=2000 AND "CLAIMTRAN"."TRANTYPE"<>'res'
    ORDER BY "CLAIMMAST"."CASENUM"

    Hope this will help

    Regards
    Sriram.R


Sign In to post your comments