SELECT
CAST(o.objectID AS VARCHAR) objectID,
o.objectName,
NULL objectNameLanguage,
NULL objectNameNote
FROM
Objects o
WHERE
o.IsVirtual = 0 AND o.IsTemplate = 0
AND o.objectName IS NOT NULL
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
CAST(c.objectID AS VARCHAR) 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
CAST(n.objectID AS VARCHAR) objectID,
n.objectName,
(CASE WHEN n.languageID != '0' THEN 'urn:cspace:pahma.cspace.berkeley.edu:vocabularies:name(languages):item:name(' + rtrim(l.MTB_ISOcode) + END')''' objectNameLanguage,+ (CASE WHEN n.objectNameTypeID != '0'charindex('/', l.language) > 0 THEN t.objectNameType substring(l.language, 1, charindex('/', l.language) - 1) ELSE l.language END) + '''' 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
;
|