Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. need help in building this view, please Edited to add results of trying RIGHT OUTER JOIN

need help in building this view, please Edited to add results of trying RIGHT OUTER JOIN

Scheduled Pinned Locked Moved Database
csharpdatabasesaleshelp
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Michael J Eber
    wrote on last edited by
    #1

    I have three primary tables: CustomerMaster ContactMaster AddressList Each customer master has a one to many relationship with contacts. Each contact has a possible 1:1 relationship with the AddressList. (ie. null addresses ok) Each address in the AddressList has a 1:1 relationship with CityEnumerators and StateEnumerators. I'm trying to get a view working that shows all contacts that are active whose CustomerMaster record is active. Unfortunately I only get the contacts that have addresses and not the ones without addresses. I thought the following query would do it....but no go. (BTW also tried RIGHT OUTER JOIN with no luck also) Any help would be appreciated as to what I'm doing that is screwing the pooch.

    SELECT TOP (100) PERCENT dbo.CustomerMaster.BSACustomerKey, dbo.ContactMaster.ContactName, dbo.ContactMaster.BusinessPhone, dbo.ContactMaster.MobilePhone,
    dbo.ContactMaster.Email, dbo.ContactMaster.FirstName, dbo.ContactMaster.LastName, dbo.ContactMaster.EmergencyMaintenance,
    dbo.ContactMaster.NormalMaintenance, dbo.ContactMaster.NetworkAbuse, dbo.ContactMaster.IssuedSwipeCard, dbo.ContactMaster.CardNumber,
    dbo.AddressList.CustomerAddressLine1, dbo.AddressList.CustomerAddressLine2, dbo.AddressList.CustomerAddressLine3, dbo.AddressList.CustomerPostBox,
    dbo.CityEnumerator.City, dbo.StateEnumerator.State, dbo.AddressList.CustomerCounty, dbo.AddressList.CustomerCountry, dbo.AddressList.CustomerZipcode,
    dbo.ContactMaster.BmcCustKey
    FROM dbo.ContactMaster INNER JOIN
    dbo.CustomerMaster ON dbo.ContactMaster.CompanyID = dbo.CustomerMaster.CustomerIdentity LEFT OUTER JOIN
    dbo.AddressList ON dbo.ContactMaster.ContactAddress = dbo.AddressList.AddressIdentity INNER JOIN
    dbo.CityEnumerator ON dbo.AddressList.CustomerCity = dbo.CityEnumerator.CityIdentity INNER JOIN
    dbo.StateEnumerator ON dbo.AddressList.CustomerStateorProvince = dbo.StateEnumerator.StateIdentity
    WHERE (dbo.CustomerMaster.CustomerStatus = 1) AND (dbo.ContactMaster.Status = 1)
    ORDER BY dbo.CustomerMaster.BSACustomerKey

    M 1 Reply Last reply
    0
    • M Michael J Eber

      I have three primary tables: CustomerMaster ContactMaster AddressList Each customer master has a one to many relationship with contacts. Each contact has a possible 1:1 relationship with the AddressList. (ie. null addresses ok) Each address in the AddressList has a 1:1 relationship with CityEnumerators and StateEnumerators. I'm trying to get a view working that shows all contacts that are active whose CustomerMaster record is active. Unfortunately I only get the contacts that have addresses and not the ones without addresses. I thought the following query would do it....but no go. (BTW also tried RIGHT OUTER JOIN with no luck also) Any help would be appreciated as to what I'm doing that is screwing the pooch.

      SELECT TOP (100) PERCENT dbo.CustomerMaster.BSACustomerKey, dbo.ContactMaster.ContactName, dbo.ContactMaster.BusinessPhone, dbo.ContactMaster.MobilePhone,
      dbo.ContactMaster.Email, dbo.ContactMaster.FirstName, dbo.ContactMaster.LastName, dbo.ContactMaster.EmergencyMaintenance,
      dbo.ContactMaster.NormalMaintenance, dbo.ContactMaster.NetworkAbuse, dbo.ContactMaster.IssuedSwipeCard, dbo.ContactMaster.CardNumber,
      dbo.AddressList.CustomerAddressLine1, dbo.AddressList.CustomerAddressLine2, dbo.AddressList.CustomerAddressLine3, dbo.AddressList.CustomerPostBox,
      dbo.CityEnumerator.City, dbo.StateEnumerator.State, dbo.AddressList.CustomerCounty, dbo.AddressList.CustomerCountry, dbo.AddressList.CustomerZipcode,
      dbo.ContactMaster.BmcCustKey
      FROM dbo.ContactMaster INNER JOIN
      dbo.CustomerMaster ON dbo.ContactMaster.CompanyID = dbo.CustomerMaster.CustomerIdentity LEFT OUTER JOIN
      dbo.AddressList ON dbo.ContactMaster.ContactAddress = dbo.AddressList.AddressIdentity INNER JOIN
      dbo.CityEnumerator ON dbo.AddressList.CustomerCity = dbo.CityEnumerator.CityIdentity INNER JOIN
      dbo.StateEnumerator ON dbo.AddressList.CustomerStateorProvince = dbo.StateEnumerator.StateIdentity
      WHERE (dbo.CustomerMaster.CustomerStatus = 1) AND (dbo.ContactMaster.Status = 1)
      ORDER BY dbo.CustomerMaster.BSACustomerKey

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Try changing the 2 inner joins after the left join to outer joins. Remove the order by to your calling method, this gets rid of the top 100% as well.

      Never underestimate the power of human stupidity RAH

      M 1 Reply Last reply
      0
      • M Mycroft Holmes

        Try changing the 2 inner joins after the left join to outer joins. Remove the order by to your calling method, this gets rid of the top 100% as well.

        Never underestimate the power of human stupidity RAH

        M Offline
        M Offline
        Michael J Eber
        wrote on last edited by
        #3

        This is my latest attempt and I still am not getting contacts who do not have addresses:

        SELECT TOP (100) PERCENT dbo.CustomerMaster.BSACustomerKey, dbo.ContactMaster.ContactName, dbo.ContactMaster.BusinessPhone, dbo.ContactMaster.MobilePhone,
        dbo.ContactMaster.Email, dbo.ContactMaster.FirstName, dbo.ContactMaster.LastName, dbo.ContactMaster.EmergencyMaintenance,
        dbo.ContactMaster.NormalMaintenance, dbo.ContactMaster.NetworkAbuse, dbo.ContactMaster.IssuedSwipeCard, dbo.ContactMaster.CardNumber,
        dbo.AddressList.CustomerAddressLine1, dbo.AddressList.CustomerAddressLine2, dbo.AddressList.CustomerAddressLine3, dbo.AddressList.CustomerPostBox,
        dbo.CityEnumerator.City, dbo.StateEnumerator.State, dbo.AddressList.CustomerCounty, dbo.AddressList.CustomerCountry, dbo.AddressList.CustomerZipcode,
        dbo.ContactMaster.BmcCustKey
        FROM dbo.ContactMaster INNER JOIN
        dbo.CustomerMaster ON dbo.ContactMaster.CompanyID = dbo.CustomerMaster.CustomerIdentity RIGHT OUTER JOIN
        dbo.AddressList ON dbo.ContactMaster.ContactAddress = dbo.AddressList.AddressIdentity LEFT OUTER JOIN
        dbo.CityEnumerator ON dbo.AddressList.CustomerCity = dbo.CityEnumerator.CityIdentity LEFT OUTER JOIN
        dbo.StateEnumerator ON dbo.AddressList.CustomerStateorProvince = dbo.StateEnumerator.StateIdentity
        WHERE (dbo.CustomerMaster.CustomerStatus = 1) AND (dbo.ContactMaster.Status = 1)
        ORDER BY dbo.CustomerMaster.BSACustomerKey

        I 1 Reply Last reply
        0
        • M Michael J Eber

          This is my latest attempt and I still am not getting contacts who do not have addresses:

          SELECT TOP (100) PERCENT dbo.CustomerMaster.BSACustomerKey, dbo.ContactMaster.ContactName, dbo.ContactMaster.BusinessPhone, dbo.ContactMaster.MobilePhone,
          dbo.ContactMaster.Email, dbo.ContactMaster.FirstName, dbo.ContactMaster.LastName, dbo.ContactMaster.EmergencyMaintenance,
          dbo.ContactMaster.NormalMaintenance, dbo.ContactMaster.NetworkAbuse, dbo.ContactMaster.IssuedSwipeCard, dbo.ContactMaster.CardNumber,
          dbo.AddressList.CustomerAddressLine1, dbo.AddressList.CustomerAddressLine2, dbo.AddressList.CustomerAddressLine3, dbo.AddressList.CustomerPostBox,
          dbo.CityEnumerator.City, dbo.StateEnumerator.State, dbo.AddressList.CustomerCounty, dbo.AddressList.CustomerCountry, dbo.AddressList.CustomerZipcode,
          dbo.ContactMaster.BmcCustKey
          FROM dbo.ContactMaster INNER JOIN
          dbo.CustomerMaster ON dbo.ContactMaster.CompanyID = dbo.CustomerMaster.CustomerIdentity RIGHT OUTER JOIN
          dbo.AddressList ON dbo.ContactMaster.ContactAddress = dbo.AddressList.AddressIdentity LEFT OUTER JOIN
          dbo.CityEnumerator ON dbo.AddressList.CustomerCity = dbo.CityEnumerator.CityIdentity LEFT OUTER JOIN
          dbo.StateEnumerator ON dbo.AddressList.CustomerStateorProvince = dbo.StateEnumerator.StateIdentity
          WHERE (dbo.CustomerMaster.CustomerStatus = 1) AND (dbo.ContactMaster.Status = 1)
          ORDER BY dbo.CustomerMaster.BSACustomerKey

          I Offline
          I Offline
          i j russell
          wrote on last edited by
          #4

          Did you even bother to read the previous answer from Mycroft?

          SELECT dbo.CustomerMaster.BSACustomerKey,
          dbo.ContactMaster.ContactName,
          dbo.ContactMaster.BusinessPhone,
          dbo.ContactMaster.MobilePhone,
          dbo.ContactMaster.Email,
          dbo.ContactMaster.FirstName,
          dbo.ContactMaster.LastName,
          dbo.ContactMaster.EmergencyMaintenance,
          dbo.ContactMaster.NormalMaintenance,
          dbo.ContactMaster.NetworkAbuse,
          dbo.ContactMaster.IssuedSwipeCard,
          dbo.ContactMaster.CardNumber,
          dbo.AddressList.CustomerAddressLine1,
          dbo.AddressList.CustomerAddressLine2,
          dbo.AddressList.CustomerAddressLine3,
          dbo.AddressList.CustomerPostBox,
          dbo.CityEnumerator.City,
          dbo.StateEnumerator.State,
          dbo.AddressList.CustomerCounty,
          dbo.AddressList.CustomerCountry,
          dbo.AddressList.CustomerZipcode,
          dbo.ContactMaster.BmcCustKey
          FROM dbo.ContactMaster
          INNER JOIN dbo.CustomerMaster
          ON dbo.ContactMaster.CompanyID = dbo.CustomerMaster.CustomerIdentity
          LEFT OUTER JOIN dbo.AddressList
          ON dbo.ContactMaster.ContactAddress = dbo.AddressList.AddressIdentity
          LEFT OUTER JOIN dbo.CityEnumerator
          ON dbo.AddressList.CustomerCity = dbo.CityEnumerator.CityIdentity
          LEFT OUTER JOIN dbo.StateEnumerator
          ON dbo.AddressList.CustomerStateorProvince = dbo.StateEnumerator.StateIdentity
          WHERE dbo.CustomerMaster.CustomerStatus = 1
          AND dbo.ContactMaster.Status = 1
          ORDER BY dbo.CustomerMaster.BSACustomerKey ASC

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups