AttributeDataSourceList break down

I decided to add this forum to keep track of solutions for DB related problems.
I have worked with some brilliant people in my life and the solutions to issues that are usually beyond something you can get at Jack in Box Jackson. They deserve historical marker. This is the historical marked on my map.
Pouzivej data base
Post Reply
hudatolah
Site Admin
Posts: 152
Joined: Thu Apr 04, 2013 8:10 pm
Are You a Headhunter?: Affirmative
Surfer?: Yes

AttributeDataSourceList break down

Post by hudatolah » Fri Aug 07, 2020 1:13 pm

Code: Select all

declare @fieldname nvarchar(128), @classname nvarchar(256), @fieldid nvarchar(32)
set @fieldname = 'Name'
set @classname = 'BMC.CORE:BMC_Computersystem'

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(1024)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1024)))+len(@fieldid)-3), 
       LEN(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1024)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1024)))+len(@fieldid)-3)) -  
       CHARINDEX('/',REVERSE(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1024)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1024)))+len(@fieldid)-3))) + 2, 
       LEN(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1024)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1024)))+len(@fieldid)-3))
       ),1,CHARINDEX(':',
       SUBSTRING(
       substring('/'+cast(cs.attributedatasourcelist as nvarchar(1024)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1024)))+len(@fieldid)-3), 
       LEN(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1024)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1024)))+len(@fieldid)-3)) -  
       CHARINDEX('/',REVERSE(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1024)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1024)))+len(@fieldid)-3))) + 2, 
       LEN(substring('/'+cast(cs.attributedatasourcelist as nvarchar(1024)),1,patindex(@fieldid,'/'+cast(cs.attributedatasourcelist as nvarchar(1024)))+len(@fieldid)-3))
       ))),
cs.Name
from BMC_CORE_BMC_ComputerSystem cs
join AST_ComputerSystem ac on cs.instanceid = ac.instance_id
join [dbo].[utf_EnumValues]('ast:attributes', 'assetlifecyclestatus') als on als.value = ac.assetlifecyclestatus 
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.display = 'Deployed'
The Blackholesurfer. My surfboard has teeth.