Asset ID Asset Name Relationship Company1234 abcd Incident 1234 abcd zxcv
1234 abcd Incident zxcv
select 'a' as column1, ' ' as column2unionselect ' ' as column1, 'b' as column2
column1 column2a b
SELECT AssetID, AssetName, MAX(Relationship) AS Relationship, MAX(Company) AS CompanyFROM myTableGROUP BY AssetID, AssetName
SELECT t.AssetID, t.AssetName, r.Relationship, c.CompanyFROM myTable tLEFT OUTER JOIN RelationshipTable r ON r.AssetID = t.AssetIDLEFT OUTER JOIN Company c ON c.AssetID = t.AssetID
Select A.AssetID, A.AssetName, B.Relate as Relationship, C.Companyfrom table and joinsunionSelect A.AssetID, A.AssetName, B.Relatedby as Relationship, C.Companyfrom table and joins
WITH CTE AS (Select A.AssetID, A.AssetName, B.Relate as Relationship, C.Companyfrom table and joinsunionSelect A.AssetID, A.AssetName, B.Relatedby as Relationship, C.Companyfrom table and joins)SELECT AssetID, AssetName, MAX(Relationship) AS Relationship, MAX(Company) AS CompanyFROM CTEGROUP BY AssetID, AssetName
SELECT distinct BASE1.AssetID AS a ,BASE1.Name As b ,case when BASE2.AssetID like 'AST%' then 'Asset Records' else '' end as c ,replace(RELA.Name,char(10),'') As d ,BASE2.AssetID AS e ,BASE2.Name AS f ,BASE1.Company AS g FROM BMC_CORE_BMC_BaseElement BASE1 (NOLOCK) LEFT JOIN BMC_CORE_BMC_BaseRelationship RELA (NOLOCK) ON BASE1.InstanceId = RELA.Source_InstanceId LEFT JOIN BMC_CORE_BMC_BaseElement BASE2 (NOLOCK) ON RELA.Destination_InstanceId = BASE2.InstanceId AND Base2.DatasetId='BMC.ASSET' LEFT JOIN AST_CMDB_Associations AST (NOLOCK) ON AST.request_id02 = BASE1.ReconciliationIdentity and AST.Request_ID02 != '0' and AST.Request_ID01 != '0' and AST.form_name01 <> 'TMS:TASK' and AST.form_name01 <> 'WOI:WorkOrder'where 1=1 and BASE1.AssetID = 'abcd'UNION ALLSELECT distinct BASE1.AssetID AS a ,BASE1.Name As b ,casewhen AST.form_name01 = 'HPD:Help Desk' then 'Incident'when AST.form_name01 = 'CHG:Infrastructure Change' then 'Infrastructure Change'when AST.form_name01 = 'PBM:Known Error' then 'Known Error'when AST.form_name01 = 'PBM:Problem Investigation' then 'Problem Investigation'when AST.form_name01 = 'RMS:Release' then 'Release'when AST.form_name01 = 'PBM:Solution Database' then 'Solution Database' end As c ,replace(CMDB_Associations.Alias_Value COLLATE DATABASE_DEFAULT,char(10),'') AS d ,AST.Request_id01 AS e ,AST.Request_Description01 AS f ,BASE1.Company AS g FROM BMC_CORE_BMC_BaseElement BASE1 (NOLOCK) LEFT JOIN BMC_CORE_BMC_BaseRelationship RELA (NOLOCK) ON BASE1.InstanceId = RELA.Source_InstanceId LEFT JOIN BMC_CORE_BMC_BaseElement BASE2 (NOLOCK) ON RELA.Destination_InstanceId = BASE2.InstanceId AND Base2.DatasetId='BMC.ASSET' LEFT JOIN AST_CMDB_Associations AST (NOLOCK) ON AST.request_id02 = BASE1.ReconciliationIdentity and AST.Request_ID02 != '0' and AST.Request_ID01 != '0' and AST.form_name01 <> 'TMS:TASK' and AST.form_name01 <> 'WOI:WorkOrder' where 1=1 and BASE1.AssetID = 'abcd'
a b c d e f gabcd SDPQ OPDAabcd SDPQ Asset Record test dcba fgh OPDA
FROM BMC_CORE_BMC_BaseElement BASE1 (NOLOCK)LEFT JOIN BMC_CORE_BMC_BaseRelationship RELA (NOLOCK) ON BASE1.InstanceId = RELA.Source_InstanceIdLEFT JOIN BMC_CORE_BMC_BaseElement BASE2 (NOLOCK) ON RELA.Destination_InstanceId = BASE2.InstanceId AND Base2.DatasetId='BMC.ASSET'LEFT JOIN AST_CMDB_Associations AST (NOLOCK) ON AST.request_id02 = BASE1.ReconciliationIdentity and AST.Request_ID02 != '0' and AST.Request_ID01 != '0' and AST.form_name01 <> 'TMS:TASK' and AST.form_name01 <> 'WOI:WorkOrder'WHERE BASE1.AssetID = 'abcd'FROM BMC_CORE_BMC_BaseElement BASE1 (NOLOCK)LEFT JOIN BMC_CORE_BMC_BaseRelationship RELA (NOLOCK) ON BASE1.InstanceId = RELA.Source_InstanceIdLEFT JOIN BMC_CORE_BMC_BaseElement BASE2 (NOLOCK) ON RELA.Destination_InstanceId = BASE2.InstanceId AND Base2.DatasetId='BMC.ASSET'LEFT JOIN AST_CMDB_Associations AST (NOLOCK) ON AST.request_id02 = BASE1.ReconciliationIdentity and AST.Request_ID02 != '0' and AST.Request_ID01 != '0' and AST.form_name01 <> 'TMS:TASK' and AST.form_name01 <> 'WOI:WorkOrder'WHERE BASE1.AssetID = 'abcd'
select A, b, MAX(C), MAX(D), MAX(E), MAX(F), gfrom( SELECT distinct BASE1.AssetID AS a ,BASE1.Name As b ,case when BASE2.AssetID like 'AST%' then 'Asset Records' else '' end as c ,replace(RELA.Name,char(10),'') As d ,BASE2.AssetID AS e ,BASE2.Name AS f ,BASE1.Company AS g FROM BMC_CORE_BMC_BaseElement BASE1 (NOLOCK) LEFT JOIN BMC_CORE_BMC_BaseRelationship RELA (NOLOCK) ON BASE1.InstanceId = RELA.Source_InstanceId LEFT JOIN BMC_CORE_BMC_BaseElement BASE2 (NOLOCK) ON RELA.Destination_InstanceId = BASE2.InstanceId AND Base2.DatasetId='BMC.ASSET' LEFT JOIN AST_CMDB_Associations AST (NOLOCK) ON AST.request_id02 = BASE1.ReconciliationIdentity and AST.Request_ID02 != '0' and AST.Request_ID01 != '0' and AST.form_name01 <> 'TMS:TASK' and AST.form_name01 <> 'WOI:WorkOrder' where 1=1 and BASE1.AssetID = 'abcd' UNION ALL SELECT distinct BASE1.AssetID AS a ,BASE1.Name As b ,case when AST.form_name01 = 'HPD:Help Desk' then 'Incident' when AST.form_name01 = 'CHG:Infrastructure Change' then 'Infrastructure Change' when AST.form_name01 = 'PBM:Known Error' then 'Known Error' when AST.form_name01 = 'PBM:Problem Investigation' then 'Problem Investigation' when AST.form_name01 = 'RMS:Release' then 'Release' when AST.form_name01 = 'PBM:Solution Database' then 'Solution Database' end As c ,replace(CMDB_Associations.Alias_Value COLLATE DATABASE_DEFAULT,char(10),'') AS d ,AST.Request_id01 AS e ,AST.Request_Description01 AS f ,BASE1.Company AS g FROM BMC_CORE_BMC_BaseElement BASE1 (NOLOCK) LEFT JOIN BMC_CORE_BMC_BaseRelationship RELA (NOLOCK) ON BASE1.InstanceId = RELA.Source_InstanceId LEFT JOIN BMC_CORE_BMC_BaseElement BASE2 (NOLOCK) ON RELA.Destination_InstanceId = BASE2.InstanceId AND Base2.DatasetId='BMC.ASSET' LEFT JOIN AST_CMDB_Associations AST (NOLOCK) ON AST.request_id02 = BASE1.ReconciliationIdentity and AST.Request_ID02 != '0' and AST.Request_ID01 != '0' and AST.form_name01 <> 'TMS:TASK' and AST.form_name01 <> 'WOI:WorkOrder' where 1=1 and BASE1.AssetID = 'abcd') xgroup by A, b, g