4

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)
`
Tom V
15.8k7 gold badges66 silver badges87 bronze badges
asked Mar 13, 2012 at 20:04
4
  • 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.. Commented 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. Commented Mar 14, 2012 at 13:42
  • I'm having the same issue - hopefully some dba.se experts can help out! Commented May 7, 2012 at 17:56
  • 1
    @JHFB answer is below if you still need it. Commented May 9, 2012 at 1:16

2 Answers 2

3

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:

http://msdn.microsoft.com/en-us/library/ms177400.aspx

answered May 8, 2012 at 8:11
1
  • 1
    Excellent, 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. Commented Jun 27, 2012 at 16:20
0
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
answered Sep 17 at 9:14
New contributor
sbrbot is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • Please add an explanation Commented Sep 17 at 11:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.