SELECT
o.objectID,
o.objectName,
NULL objectNameLanguage,
NULL objectNameNote
FROM
Objects o
WHERE
o.IsVirtual = 0 AND o.IsTemplate = 0
UNION ALL
SELECT
'c' + CAST(c.componentID AS VARCHAR) objectID,
c.componentName objectName,
NULL objectNameLanguage,
NULL objectNameNote
FROM
ObjComponents c
WHERE
c.objectID IN (SELECT t.objectID FROM ObjComponents t GROUP BY t.objectID HAVING count(*) > 1)
AND c.componentName IS NOT NULL
UNION ALL
SELECT
c.objectID,
c.componentName objectName,
NULL objectNameLanguage,
'Component name' objectNameNote
FROM
ObjComponents c
JOIN Objects o ON c.objectID = o.objectID
WHERE
o.IsVirtual = 0 AND o.IsTemplate = 0
AND c.objectID IN (SELECT t.objectID FROM ObjComponents t GROUP BY t.objectID HAVING count(*) = 1)
AND c.componentName IS NOT NULL
AND coalesce(o.objectName,'') != c.componentName
UNION ALL
SELECT
n.objectID,
n.objectName,
(CASE WHEN n.languageID != '0' THEN l.language END) objectNameLanguage,
(CASE WHEN n.objectNameTypeID != '0' THEN t.objectNameType ELSE '' END) + (CASE WHEN n.objectNameTypeID != '0' AND n.remarks is not null THEN '; ' ELSE '' END) + coalesce(n.remarks, '') objectNameNote
FROM
objectNames n
LEFT OUTER JOIN objectNameTypes t ON n.objectNameTypeID = t.objectNameTypeID
LEFT OUTER JOIN languages l ON n.languageID = l.languageID
WHERE
n.objectName IS NOT NULL
;
|