In SQL 2008 R2, I'm putting together some administrative queries on SSRS metadata to check proper configuration, and other sorts of proactive things.
While querying the ReportServer db, I've been successful in checking reports, shared data sources, etc. The one thing that I am having trouble with is querying for any value within the Subscriptions.MatchData
column. Everything from this column comes back as NULL (unless I return the entire contents of the column).
Specifically, I need the value for EndDate
. I've tried a number of tweaks to no avail, including toying around with XPath, XMLNamespace, etc. I found this basic example of how it is supposed to work in 2005. What is different about 2008 that this will not work? And how can I query this value in 2008 R2?
`
SELECT
[Description]
,x.m.value('StartDateTime[1]','varchar(30)') AS StartDateTime
,x.m.value('EndDate[1]','varchar(10)') AS EndDate
FROM
(
SELECT
[description]
,CAST(MatchData AS XML) AS MatchData
FROM ReportServer.dbo.Subscriptions
) AS P
CROSS APPLY MatchData.nodes('//ScheduleDefinition') x(m)
`
-
What exactly do you need here? Default dates as in 1 week/month/year ago? Do you want to be able to edit these dates in reports and do you want mail subscriptions to automatically enter dates each time it is sent i.e weekly monthhly etc..Axle– Axle2012年03月14日 13:37:41 +00:00Commented Mar 14, 2012 at 13:37
-
If you run the script, you see that it returns null instead of giving me the EndDate value found in the XML contained within ReportServer.dbo.Subscriptions.MatchData. I have a bigger query working to verify correct data sources based on how we implement and organize our ssrs reports. I want to be able to also include the Subscription's End Date to the results so that I can also provide an alert if this is an active subscription. I think this is more of a "how do I query the XML correctly?" question than a "am I looking in the right place?" question. This is the value that I need.dev_etter– dev_etter2012年03月14日 13:42:56 +00:00Commented Mar 14, 2012 at 13:42
-
I'm having the same issue - hopefully some dba.se experts can help out!JHFB– JHFB2012年05月07日 17:56:59 +00:00Commented May 7, 2012 at 17:56
-
1@JHFB answer is below if you still need it.WT_W– WT_W2012年05月09日 01:16:05 +00:00Commented May 9, 2012 at 1:16
2 Answers 2
What's throwing it off is the XML name spaces in the tags. To get around this you need to use the with XMLNameSpaces
clause.
Give this query a go. I've tested this on a test instance (2008, not 2008 r2), so you may need to change the actual namespace definition to match your xml data.
with xmlnamespaces('http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices' as rs)
SELECT
[Description]
,m.value('rs:StartDateTime[1]','varchar(30)') AS StartDateTime
,m.value('rs:EndDate[1]','varchar(30)') AS EndDate
FROM
(
SELECT
[description],
CAST(MatchData AS XML) AS MatchData
FROM ReportServer.dbo.Subscriptions
) AS P
CROSS APPLY MatchData.nodes('/ScheduleDefinition') x(m)
SQL BOL reference for the WITH XMLNAMESPACES
clause:
-
1Excellent, thank you so much! I had tried one or two namespaces that are used in my other SSRS metadata scripts, but to no avail. Thanks for the link too.dev_etter– dev_etter2012年06月27日 16:20:56 +00:00Commented Jun 27, 2012 at 16:20
WITH XMLNameSpaces('http://schemas.microsoft.com/sqlserver/reporting/2010/03/01/ReportServer' AS ns)
SELECT
SubscriptionID,
Description,
CAST(MatchData AS XML).value('(/ScheduleDefinition/ns:StartDateTime)[1]','DATETIME') AS StartDateTime,
CAST(MatchData AS XML).value('(/ScheduleDefinition/ns:EndDate)[1]','DATETIME') AS EndDate
FROM Subscriptions
-
Please add an explanationRohit Gupta– Rohit Gupta2025年09月17日 11:28:18 +00:00Commented Sep 17 at 11:28
Explore related questions
See similar questions with these tags.