0

Every or some ssrs reports have following tags:

xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition"
xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner"
xmlns:df="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition/defaultfontfamily"
MustUnderstand="df"

This query doesn't return any data unless I remove the attributes specified above. In the given xml, attributes can't be removed.

declare @content xml =
'<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition" xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:df="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition/defaultfontfamily" MustUnderstand="df">
  <DataSets>
    <DataSet Name="DS">
      <Query>
        <CommandText>rep.my_proc</CommandText>
      </Query>
    </DataSet>
  </DataSets>
</Report>'

  select 
      'DB growth' as ReportName, 
      CommandText = x.value('(Query/CommandText)[1]','VARCHAR(250)')
  from  @content.nodes('Report/DataSets/DataSet') r (x)

Is there any error in that query?

1
  • 1
    Add WITH XMLNAMESPACES(DEFAULT 'http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition' ) before the SELECT Commented Jan 23, 2020 at 10:33

1 Answer 1

1

Take a look at WITH XMLNAMESPACES

declare @content xml =
'<Report xmlns="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition"     xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:df="http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition/defaultfontfamily" MustUnderstand="df">
  <DataSets>
    <DataSet Name="DS">
      <Query>
        <CommandText>rep.my_proc</CommandText>
      </Query>
    </DataSet>
  </DataSets>
</Report>'

;WITH XMLNAMESPACES(DEFAULT 'http://schemas.microsoft.com/sqlserver/reporting/2016/01/reportdefinition')
select 
    'DB growth' as ReportName, 
    CommandText = x.value('(Query/CommandText)[1]','VARCHAR(250)')
from @content.nodes('Report/DataSets/DataSet') r (x)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.