Returning XML Value for Extended Event I would like to get the filepath for my extended event event_file and put it inside a variable but I'm stuck.

Here's what I have:

DECLARE @ExpensiveXML XML 

SET @ExpensiveXML = (SELECT CAST(xet.target_data AS xml) AS 'XML'
                    FROM sys.dm_xe_session_targets AS xet
                    JOIN sys.dm_xe_sessions AS xe
                    ON (xe.address = xet.event_session_address)
                    WHERE xe.name = '&lt;my extended event&gt;');

SELECT @ExpensiveXML.query('/EventFileTarget/File')


and it returns:

&lt;File name="MyFilePath.xel" /&gt;


I would like to only return MyFilePath.xel without the &lt; File name=.../ > around it.
Use value() instead. 

The value() function returns a scalar value and takes two parameters. The first is the xpath expression and the second is the data type you want.

@ExpensiveXML.value('(/EventFileTarget/File/@name)[1]', 'nvarchar(260)');