BanisterMurray of Spaghetti
7/16/2015 - 1:43 PM

How to Join Orgs to Sites

How to Join Orgs to Sites


-- Site by Org

select s.*
     from StickyFish.dbo.Organization a with(nolock)
left join StickyFish.dbo.OrganzationMap om with(nolock)
      on a.OrgID = om.OrgID
left join StickyFish.dbo.DataObjectStore d with(nolock) 
      on om.DataObjectStoreID = d.DataObjectStoreID
left join StickyFish.dbo.DataObjectStoreIdentityField df with(nolock)
      on d.DataObjectStoreID = df.DataObjectStoreID
      and df.SourceFieldID = 99
left join StickyFish.dbo.Sites s with(nolock)
      on df.FieldValue = s.SiteID
   where a.OrgID = '90F70E7C-7BCE-4FE7-9AA7-1A21CC077B78'
   
   
   
   
-- Org by Site

select a.*
     from StickyFish.dbo.Organization a with(nolock)
left join StickyFish.dbo.OrganzationMap om with(nolock)
      on a.OrgID = om.OrgID
left join StickyFish.dbo.DataObjectStore d with(nolock) 
      on om.DataObjectStoreID = d.DataObjectStoreID
left join StickyFish.dbo.DataObjectStoreIdentityField df with(nolock)
      on d.DataObjectStoreID = df.DataObjectStoreID
      and df.SourceFieldID = 99
left join StickyFish.dbo.Sites s with(nolock)
      on df.FieldValue = s.SiteID
   where s.SiteID = 1670