IF NOT EXISTS (SELECT * FROM sys.columns where object_id = OBJECT_ID(N'[AKUZ].[T_ADDRESS]') and name = 'AOGUID')
ALTER TABLE [AKUZ].[T_ADDRESS] ADD [AOGUID] uniqueidentifier NULL
GO

IF NOT EXISTS (SELECT * FROM sys.columns where object_id = OBJECT_ID(N'[AKUZ].[T_ADDRESS]') and name = 'HouseGUID')
ALTER TABLE [AKUZ].[T_ADDRESS] ADD [HouseGUID] uniqueidentifier NULL
GO

update addr
set HouseGuid = fulladdr.HouseGuid, 
	AOGUID = fulladdr.AOGUID
from akuz.T_ADDRESS addr
	join fias.T_FullADDR2 fulladdr on fulladdr.AddrID = addr.FullADDR2
where addr.FullADDR2 is not null
go

update addr
set HouseGuid = fulladdr.HouseGuid, 
	AOGUID = fulladdr.AOGUID
from akuz.T_ADDRESS addr
	join fias.T_FullAddr fulladdr on fulladdr.AddrID = addr.Addrobj
where addr.Addrobj is not null and addr.HouseGUID is null and addr.AOGUID is null
go