use Polaris

CREATE TABLE #Branch (AttrID int, OrgID int, ParentOrgID int, Value NVARCHAR(255))
INSERT INTO #Branch
select
    opp.AttrID,
    opp.OrganizationID,
    o.ParentOrganizationID,
    oPP.[Value]
FROM polaris.OrganizationsPPPP oPP (nolock)
INNER join polaris.Organizations o (nolock)
    on oPP.OrganizationID = o.OrganizationID
WHERE o.OrganizationCodeID = 3
Group BY
    opp.AttrID,
    opp.OrganizationID,
    o.ParentOrganizationID,
    oPP.[Value]



select
    aa.Mnemonic,
    aac.AttrClassDesc,
    aa.AttrID,
    aa.AttrDesc,
    o.name Library,
    ob.OrganizationID BranchID,
    ob.name Branch,
    opp.[Value] "Library_Setting",
    b.[Value] "Branch_Setting"
FROM polaris.AdminAttributes aa (nolock)
left join polaris.AdminAttributeClasses aac (nolock)
    on aa.AttrClassID = aac.AttrClassID
left join polaris.AdminAttributeTypes aat (nolock)
    on aa.AttrTypeID = aat.AttrTypeID
left join polaris.AdminGroup ag (nolock)
    on aa.AttrID = ag.AttrID
left join polaris.AdminCategories ac (nolock)
    on ag.AdminCategoryID = ac.AdminCategoryID
left join polaris.Domains d (nolock)
    on ac.DomainID = d.DomainID
left join polaris.OrganizationsPPPP oPP (nolock)
    on aa.AttrID = oPP.AttrID
left join polaris.Organizations o (nolock)
    on oPP.OrganizationID = o.OrganizationID
left join polaris.Organizations op (nolock)
    on o.ParentOrganizationID = op.OrganizationID
INNER JOIN #Branch b
    on aa.AttrID = b.AttrID and opp.OrganizationID = b.ParentOrgID
INNER JOIN Polaris.Organizations ob (nolock)
    on b.OrgID = ob.OrganizationID
WHERE (ac.DomainID not in (8,16,32,64,128,256,512) OR ac.DomainID is null)
and o.OrganizationCodeID = 2
and opp.[Value] != b.[Value]
-- The below are mostly organizational-level settings like address and contact details, and some PAC settings
and opp.AttrID not in (1621,2428,212,12,11,	1,10,2,6,7,2377,2645,2946,2943,2945,2942,2944,2947)
Group BY
    aa.Mnemonic,
    aac.AttrClassDesc,
    aa.AttrID,
    aa.AttrDesc,
    o.name,
    ob.OrganizationID,
    ob.name,
    opp.[Value],
    b.[Value]
Order BY
    aa.Mnemonic,
    aa.AttrDesc,
    ob.name,
    opp.[Value],
    b.[Value]

    /*

CONTROL FLAGS
 bit 0 - System, bit 1 - Library, bit 2 - Branch, bit 3 - Collection, bit 4 - Workstation, bit 5 - User, bit 6 - Patron, bit 7 - Database, bit 8 - Server

    */

    DROP TABLE #Branch