Login to participate
Endpoint Management & Virtualization ArticlesRSS

How to Use AuxData in Queries

Fabrice B M Raud's picture

I customize the Altiris Helpdesk Solutions since many years and never did find useful the AuxData because of the Query limitation.

Finally, one day, I decided to spend some time with my friend Geoffroy Perrier and we found the solution.

First you have to create a view using this script:

-- Begin of the create view script
Use Altiris_Incidents
Go

create view ZFAB_vAuxData
as
select id,x.value('(value)[1]','nvarchar(MAX)') AS colvalue, x.value('(name)[1]','nvarchar(MAX)') AS colname
From 
(
select id, cast(auxdata as xml) auxdata from workitem
)
s
CROSS APPLY auxdata.nodes('AuxDataDataSet/*') det(x)

-- End of the create view script

Next, to query the workitems with their AuxData you have to join the workitem_current_view or the workitem_detail_view with the ZFAB_vAuxData view using the id column:

-- Begin of Query
Select * from workitem_current_view
inner join ZFAB_vAuxData on workitem_current_view.workitem_id = ZFAB_vAuxData.id
-- End of Query

By this way you will display as records as entries in the AuxData container for the current workitem record.

To filter on a member of the AuxData container add a condition on the colname column of the ZFAB_vAuxData view such as:

-- Begin of Query
Select * from workitem_current_view
inner join ZFAB_vAuxData on workitem_current_view.workitem_id = ZFAB_vAuxData.id
Where colname = 'survey_complete'
-- End of Query

This will return a colvalue value of 'false' or 'true' depends if the satisfaction survey was sent or not.

It is also possible to combine the conditions such as:

-- Begin of Query
Select * from workitem_current_view
inner join ZFAB_vAuxData on workitem_current_view.workitem_id = ZFAB_vAuxData.id
Where colname = 'survey_complete' and colvalue = 'false'
-- End of Query

To use the ZFAB_vAuxData view in the Altiris reports use the following script under SQL:

-- Begin of create view in Altiris
Use Altiris
Go
Create view HD_ZFAB_vAuxData as
Select * from altiris_incidents.dbo.ZFAB_vAuxData

-- End of create view in Altiris

matzebru's picture

Is there a way to get this

Is there a way to get this to work in SQL 2000? I got an "Incorrect syntax near 'APPLY'" error when trying to create the view. Thanks

EFMagnuson's picture

Alternate soltuion with SQL 2007

We have Helpdesk running on a SQL 2007 backbone, and because of that we have few new methodsavailable that make this somewhat easier and does not requrie creating any new views.

For this example I will use a query I set up that looks for a custom bit of AuxData we use with an automated Task to send e-mail remiders to the customer that we are awaiting their feedback.

Here is the query:

SET ARITHABORT ON

SELECT hd1.workitem_number
FROM dbo.HD_workitem_current_view hd1     
WHERE CAST(hd1.workitem_auxdata as xml).exist('/AuxDataDataSet/PendingCountdown/name/text() [contains(.,"Days")]') = 1 
	AND CAST(hd1.workitem_auxdata as xml).value('(/AuxDataDataSet/PendingCountdown/value) [1]', 'tinyint') > 0

The ".exist()" does exactly what the queries in the parent post do i.e. it returns a True/False (0/1) value the queried xml. Just

The ".value()" is useful in this case as it can compare a numeric value in the dataset. Here we want it to see anything with a value greater-than (>) zero.

Dominique's picture

I was waiting for this fopr

I was waiting for this fopr awhile thanks

Dom