Code: Select all
declare @fieldname nvarchar(75), @classname nvarchar(18), @fieldid nvarchar(32)
set @fieldname = 'Name'
set @classname = 'BMC.CORE:BMC_Computersystem'
-- SELECT max(len(Name)),max(len(classid)),max(len(attributedatasourcelist)) from BMC_CORE_BMC_ComputerSystem where AttributeDatasourcelist is NOT NULL and Datasetid = 'BMC.ASSET'
set @fieldid = '%'+(select cast(fieldid as nvarchar(32)) from field where schemaid = (select schemaid from arschema where name = @classname) and fieldname = @fieldname)+'%';
select
substring(
SUBSTRING(
substring(':'+cast(cs.attributedatasourcelist as nvarchar(1101)),1,patindex(@fieldid,':'+cast(cs.attributedatasourcelist as nvarchar(1101)))+len(@fieldid)-3),
LEN(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1101)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1101)))+len(@fieldid)-3)) -
CHARINDEX('/',REVERSE(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1101)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1101)))+len(@fieldid)-3))) + 2,
LEN(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1101)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1101)))+len(@fieldid)-3))
),1,CHARINDEX(':',
SUBSTRING(
substring('/'+cast(cs.attributedatasourcelist as nvarchar(1101)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1101)))+len(@fieldid)-3),
LEN(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1101)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1101)))+len(@fieldid)-3)) -
CHARINDEX('/',REVERSE(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1101)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1101)))+len(@fieldid)-3))) + 2,
LEN(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1101)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1101)))+len(@fieldid)-3))
))) AS List,
cs.Name,
cs.DatasetId
from BMC_CORE_BMC_ComputerSystem cs
join AST_ComputerSystem ac on cs.ReconciliationIdentity = ac.reconciliation_identity
-- join [dbo].[utf_EnumValues]('ast:attributes', 'assetlifecyclestatus') als on als.value = ac.assetlifecyclestatus
join ast_attributes als on als.ReconciliationIdentity = cs.reconciliationidentity
where cs.DatasetId = 'BMC.ASSET'
--and cs.name not like 'k%'
--and cs.Type = 'Server'
--and cs.item not in ('Appliance','Blade Enclosure','Chassis','Console','Onboard Administrator','Other')
--and cs.name != 'Deactivated Computer'
--and cs.name != 'VM no longer being discovered'
--and cs.name != 'VM no longer in Vcenter'
and als.assetLifecycleStatus = '7'
and cs.AttributeDataSourceList IS NOT NULL