Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Query Issues

Status
Not open for further replies.

kentover

MIS
Aug 21, 2002
41
US
I pull the following XML from a field in SQL Server 2008 and need to query into the string to get the values. Each attempt has returned NULL or nothing at all.

Code:
<ScheduleDefinition xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance">[/URL]
	<StartDateTime xmlns="[URL unfurl="true"]http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices">2010-11-19T15:35:00.000-06:00</StartDateTime>[/URL]
	<WeeklyRecurrence xmlns="[URL unfurl="true"]http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices">[/URL]
		<WeeksInterval>1</WeeksInterval>
		<DaysOfWeek>
			<Monday>true</Monday>
			<Tuesday>true</Tuesday>
			<Wednesday>true</Wednesday>
			<Thursday>true</Thursday>
			<Friday>true</Friday>
		</DaysOfWeek>
	</WeeklyRecurrence>
</ScheduleDefinition>

The following code is used to return values. I have been able to use the code for other XML strings but this one fails. Just FYI - This is data from the SSRS Subscriptions table in the MatchData field. MSDN articles place the StartDateTime inside WeeklyRecurrence but that is not actually true.

Code:
DECLARE		@TO XML 
DECLARE		@String VARCHAR(MAX)


SELECT		@TO = MatchData
FROM		[ReportServer].dbo.Subscriptions 
WHERE		SubscriptionID = '9B1AF007-00AB-45E0-9C26-386E49BE926B'

SELECT		@String = @TO.value (N'(/ScheduleDefinition/StartDateTime)[1]',N'VARCHAR(MAX)')


SELECT		@String AS TEST

Thanks in advance for any help.
KO
 
OK, I found the answer. It is ugly but works when you strip out the XML tags. Here is what worked.

Code:
DECLARE		@TO XML 
DECLARE		@String NVARCHAR(MAX)


SELECT		@TO = REPLACE(REPLACE(CAST(MatchData AS NVARCHAR(MAX)),' xmlns:xsd="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema"[/URL] xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"',''),'[/URL] xmlns="[URL unfurl="true"]http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices"','')[/URL]
FROM		[ReportServer].dbo.Subscriptions 
WHERE		SubscriptionID = '9B1AF007-00AB-45E0-9C26-386E49BE926B'


SELECT		@String = @TO.value (N'(/ScheduleDefinition//Monday)[1]',N'VARCHAR(MAX)')


SELECT		@String AS TEST
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top