-- 性能优化数据升级
update t_haos_adminorg org
set flevel = (select top 1 struct.flevel
              from t_haos_adminstruct struct
              where struct.fadminorgid = org.fboid
                and struct.fiscurrentversion = '1' and fstructprojectid = 1010)
where fdatastatus = '1'
  and exists(
        select 1
              from t_haos_adminstruct struct
              where struct.fadminorgid = org.fboid
                and struct.fiscurrentversion = '1' and fstructprojectid = 1010
    );


update t_haos_adminorg  org
set fstructlongnumber = (select top 1 struct.fstructlongnumber
                         from t_haos_adminstruct struct
                         where struct.fadminorgid = org.fboid
                           and struct.fiscurrentversion = '1' and fstructprojectid = 1010)
where fdatastatus = '1'
  and exists(
        select 1
        from t_haos_adminstruct struct
        where struct.fadminorgid = org.fboid
          and struct.fiscurrentversion = '1' and fstructprojectid = 1010
    );

update t_haos_adminorg  org
set fsortcode = (select top 1 sortcode.fsortcode
                 from t_haos_orgsortcode sortcode
                 where sortcode.fadminorgid = org.fboid
                   and sortcode.fiscurrentversion = '1')
where fdatastatus = '1'
  and exists(
        select 1
        from t_haos_orgsortcode sortcode
        where sortcode.fadminorgid = org.fboid
          and sortcode.fiscurrentversion = '1'
    );


update t_haos_orgteam  ot
set flevel = (select top 1 struct.flevel
              from t_haos_orgteamstruct struct
              where struct.forgteamid = ot.fboid
                and struct.fiscurrentversion = '1' and fstructprojectid = 1010)
where fdatastatus = '1' and fotclassify = 1010
  and exists(select struct.flevel
              from t_haos_orgteamstruct struct
              where struct.forgteamid = ot.fboid
                and struct.fiscurrentversion = '1' and fstructprojectid = 1010);

update t_haos_orgteam  ot
set fstructlongnumber = (select top 1 struct.fstructlongnumber
                         from t_haos_orgteamstruct struct
                         where struct.forgteamid = ot.fboid
                           and struct.fiscurrentversion = '1' and fstructprojectid = 1010)
where fdatastatus = '1'  and fotclassify = 1010
  and exists(select struct.fstructlongnumber
                         from t_haos_orgteamstruct struct
                         where struct.forgteamid = ot.fboid
                           and struct.fiscurrentversion = '1' and fstructprojectid = 1010);

update t_haos_orgteam  ot
set fsortcode = (select top 1 sortcode.fsortcode
                 from t_haos_orgsortcode sortcode
                 where sortcode.fadminorgid = ot.fboid
                   and sortcode.fiscurrentversion = '1')
where fdatastatus = '1'  and fotclassify = 1010
  and exists(
        select 1
        from t_haos_orgsortcode sortcode
        where sortcode.fadminorgid = ot.fboid
          and sortcode.fiscurrentversion = '1'
    );