Results 1 to 11 of 11
  1. #1
    Join Date
    Jun 2005
    Location
    Denver, CO
    Posts
    100

    Unanswered: Exclude NULL values for "conditional" SELECT query

    I'm writing a query for a Reporting Services report (.rdl). There are a few elements of the query that are causing it to return 0 results as they do not apply in every situation. For instance, I have a property description that has related land survey data associated with it. For simplicity sake let's call the land survey data A. Based on the source of the data it can have data in B1,B2,B3 OR C1,C2,C3 but not both. I'm writing the SELECT query to contain both types (B and C) because this is for a report definition and I don't know in advance which fields are populated.

    I used the query designer the query so it's not throwing any errors, but it's not giving me any date either. I'm sure this is because the long query with all the joins does not satisfy everything, but I don't know how to give it any more defined parameters. Any help or guidance would be appreciated...Thanks!

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Any code with DDL, sample data and expect results would help
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Post your code. we do not play blind chess. read instructions in the sticky.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by Thrasymachus
    Post your code. we do not play blind chess. read instructions in the sticky.

    BRILLIANT

    (Can I have my Guinness now?)
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by Thrasymachus
    Post your code. we do not play blind chess. read instructions in the sticky.

    wait...wait...wait....I know someone who does....

    http://www.dbforums.com/members/blindman.html
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  6. #6
    Join Date
    Jun 2005
    Location
    Denver, CO
    Posts
    100
    I've reduced the size of the query for purposes of debugging. This query returns 98 rows of dummy data:
    Code:
    SELECT  d.DeedId, 
            d.DeedReference, 
            d.RecordedDate, 
            d.GrossAcres AS DeedGrossAcres, 
            d.NetAcres AS DeedNetAcres, 
            d.Volume AS DeedVolume, 
            d.Page AS DeedPage, 
            d.Comments, 
            c.County, 
            s.[State]
    FROM 
        tbl_Deed d
    INNER JOIN tbl_County c
        ON d.CountyId = tbl_County.CountyId 
    INNER JOIN tbl_State s
        ON d.StateId = s.StateId
    When I add more to the query it only returns 84 rows:

    Code:
    SELECT  d.DeedId, 
            d.DeedReference, 
            d.RecordedDate, 
            d.GrossAcres AS DeedGrossAcres, 
            d.NetAcres AS DeedNetAcres, 
            d.Volume AS DeedVolume, 
            d.Page AS DeedPage, 
            d.Comments, 
            c.County, 
            s.[State], 
            ci.ConveyedInterestId, 
            ci.InterestConveyed
    FROM    
        tbl_Deed d
    INNER JOIN tbl_County c
        ON d.CountyId = c.CountyId 
    INNER JOIN tbl_State 
        ON d.StateId = s.StateId 
    INNER JOIN tbl_ConveyedInterest ci
        ON d.DeedId = ci.DeedId
    I've only added two more fields from one more table. I didn't post code before because it's very long and I was only thinking conceptually, but thanks.

  7. #7
    Join Date
    Feb 2009
    Posts
    51
    I think a Left Outer join will suffice rather than inner join.
    Thanks

  8. #8
    Join Date
    Jun 2005
    Location
    Denver, CO
    Posts
    100
    Thank you. It looks like they may have duplicated some of the results. I went from 92 to 108.

    Does the query designer only handle inner joins?
    Last edited by BillSinc; 02-19-09 at 22:18.

  9. #9
    Join Date
    Jun 2005
    Location
    Denver, CO
    Posts
    100
    Actually I think it's right. It looks like I'm going to need to manually build the query. Thanks for your help!
    BillS

  10. #10
    Join Date
    Feb 2009
    Posts
    51
    It does support other joins right click on the join line (grphical representaion)
    from the context menu select all rows from either the Left or right table
    that would chage the join type to left outer or right outer respectively.

  11. #11
    Join Date
    Jun 2005
    Location
    Denver, CO
    Posts
    100
    Thanks, I discovered that last night.
    BillS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •