选择table.object_type并选择table。*不要为object_type返回相同的值

时间:2019-10-29 10:24:39

标签: select enterprise-architect

我正在尝试选择链接到对象的所有“应用程序功能”。因此,我阅读了以下查询:

select 
other.ea_guid as CLASSGUID, other.object_type as CLASSTYPE,
obj.name, 
other.*
from  t_object as obj
join (
        select t_connector.start_object_id as Object2_id, t_object.* from t_object 
                join t_connector on t_connector.end_object_id=t_object.Object_id
                where t_object.object_type =  'Application Function'
        union
        select t_connector.end_object_id as Object2_id, t_object.*  from t_object  
                join t_connector on t_connector.start_object_id=t_object.Object_id
                where t_object.object_type =  'Application Function'

        ) as other on obj.Object_id=other.Object2_id
where obj.object_id = 143299

它是空的。

没有where子句,它将返回: select * result

但是,如果我通过other.*之类的命名列来选择other.object_type, object_name,则obj.name列将为空,而other.object_type则为另一个值: named select result

我认为这种差异解释了为什么我的选择不起作用。但是如何解释和解决这个问题?

1 个答案:

答案 0 :(得分:2)

当查询返回时,

EA对某些字段执行特殊的魔术

它基于返回的字段的确切名称(例如Object_TypeNote)来执行此操作 为避免这种情况,请确保为这些字段指定其他别名。例如Object_Type as theRealType

在这种情况下,我将假设您正在寻找ArchiMate应用程序功能。实际上这是一个应用程序功能,实际上存储在 Stereotype 中,而不是在 Object_Type

中存储

这样的查询应返回链接到ID为143299的对象的所有ArchiMate应用程序功能

select o2.Object_ID AS CLASSGUID, o2.Object_Type AS CLASSTYPE, o2.Object_Type as theRealObjectType,
o2.*
from t_object o 
inner join t_connector c on c.Connector_ID in (c.Start_Object_ID, c.End_Object_ID)
inner join t_object o2 on o2.Object_ID in (c.Start_Object_ID, c.End_Object_ID)
                        and o2.Object_ID <> o.Object_ID
where o.Stereotype = 'ArchiMate_ApplicationFunction'
and o2.Object_ID = 143299

此查询已在SQL Server存储库中编写和测试。如果要在.eap文件上使用它(MS Access SQL语法),可能需要进行调整