sql - Left Outer Join Query returns too many rows -


i'm having issue trying data 4 tables. i've tried 4 left outer joins , i'm trying subselect. try ad.accountdirecttocommitmentitemcategoryid field, query goes returning desired 4 rows 16 rows. i'm trying add column results duplicating each row each data in column. how should writing query differently?

  select distinct  ad.accountdirecttocommitmentitemcategoryid, cic.commitmentitemcategoryname, cict.commitmentitemcategorytypename, cic.commitmentitemcategorytypeid, cic.commitmentitemcategoryid, vw.dollarsallocated   [dbo].[tblcommitmentitemcategory] cic   left outer join [dbo].vw_parentaccountdollarsallocatedbycommitmentitemcategory] vw    on vw.commitmentitemcategoryid = cic.commitmentitemcategoryid    left outer join [dbo].[tblcommitmentitemcategorytype] cict    on cic.commitmentitemcategorytypeid = cict.commitmentitemcategorytypeid      left outer join (     select distinct accountdirecttocommitmentitemcategoryid, accountdirectparentid [dbo].[tblaccountdirecttocommitmentitemcategory] adtcic     adtcic.accountdirectparentid = 6478) ad    on     /*(ad.accountdirecttocommitmentitemcategoryid = vw.commitmentitemcategoryid)   gets 4 rows first column null */    (ad.accountdirectparentid = vw.accountdirectparentid)  /*returns 16 rows */    fiscalyear = 2015 , vw.accountdirectparentid = 6478    order cic.commitmentitemcategoryname 

it wouldn't let me post image of results because i'm newbie. hope helps...

accountdirecttocommitmentitemcategoryid commitmentitemcategoryname  commitmentitemcategorytypename  commitmentitemcategorytypeid    commitmentitemcategoryid    dollarsallocated 6   23**    contractual 1   2   1200.00 7   23**    contractual 1   2   1200.00 8   23**    contractual 1   2   1200.00 9   23**    contractual 1   2   1200.00 6   25**    contractual 1   1   1100.00 7   25**    contractual 1   1   1100.00 8   25**    contractual 1   1   1100.00 9   25**    contractual 1   1   1100.00 6   26**    supplies    3   3   1300.00 7   26**    supplies    3   3   1300.00 8   26**    supplies    3   3   1300.00 9   26**    supplies    3   3   1300.00 6   31**    equipment   2   5   500.00 7   31**    equipment   2   5   500.00 8   31**    equipment   2   5   500.00 9   31**    equipment   2   5   500.00 

linq solution: i'm not getting 0 dollars row when no category match: able figure out offending column parentid needing specfied again in clause. , created linq query it. unfortunately i'm not getting 0 dollars entry when there no matching cic category used before. thoughts?

var querydollars = cic in johncontext.tblcommitmentitemcategory    join vw in johncontext.vw_parentaccountdollarsallocatedbycommitmentitemcategory         on new { commitmentitemcategory = cic.commitmentitemcategoryid, fiscalyear = 2015, parentaccountid = 6478 }             equals new { commitmentitemcategory = vw.commitmentitemcategoryid, fiscalyear = vw.fiscalyear, parentaccountid = vw.accountdirectparentid }    t    vw in t.defaultifempty()    join cict in johncontext.tblcommitmentitemcategorytype    on cic.commitmentitemcategorytypeid equals cict.commitmentitemcategorytypeid    join ad in johncontext.tblaccountdirecttocommitmentitemcategory    on vw.commitmentitemcategoryid equals ad.commitmentitemcategoryid    ad.accountdirectparentid == 6478    let displaycategory = cic.commitmentitemcategoryname + " ( " + cict.commitmentitemcategorytypename + " )" // called categorytype it's id below    let displaycategorytypeid = "categorytype_" + ad.accountdirecttocommitmentitemcategoryid.tostring() //   let displaycategorytypeid = "categorytype_" + cic.commitmentitemcategoryid.tostring()    let displaydollarsallocated = vw.dollarsallocated == null ? 0 : vw.dollarsallocated    orderby cic.commitmentitemcategoryname    select new    {        displaycategory,        displaycategorytypeid,        cic.commitmentitemcategoryid,        displaydollarsallocated    }; 


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -