SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Xml parsing issue/question


Xml parsing issue/question

Author
Message
pamozer
pamozer
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1881 Visits: 443
So I have the following xml that is stored in a table
<root>
<ENCOUNTER.ENCOUNTERSTATUSDESCRIPTION>
<OldValue>Draft</OldValue>
<NewValue>Approved</NewValue>
<DisplayName>Status</DisplayName>
</ENCOUNTER.ENCOUNTERSTATUSDESCRIPTION>
<ENCOUNTER.ADDONS>
<OldValue>0</OldValue>
<NewValue>2</NewValue>
<DisplayName>Addn Ons</DisplayName>
</ENCOUNTER.ADDONS>



If I run the following I get back the results I expect
DECLARE @rules TABLE (ID INT, XmlRule XML)

INSERT INTO @rules VALUES(1, '<root>
<ENCOUNTER.ENCOUNTERSTATUSDESCRIPTION>
<OldValue>Draft</OldValue>
<NewValue>Approved</NewValue>
<DisplayName>Status</DisplayName>
</ENCOUNTER.ENCOUNTERSTATUSDESCRIPTION>
<ENCOUNTER.ADDONS>
<OldValue>0</OldValue>
<NewValue>2</NewValue>
<DisplayName>Addn Ons</DisplayName>
</ENCOUNTER.ADDONS>
</root>')


SELECT

T.Col.value('NewValue[1]','varchar(50)') AS 'Operation'

FROM @rules r
CROSS APPLY XmlRule.nodes('/root/ENCOUNTER.ENCOUNTERSTATUSDESCRIPTION') AS T(Col)


RESULTS:

StatusDescription
Approved


IF I run the following:

SELECT
--Al.CreatedDate,
t.b.value('NewValue[1]','varchar(50)') StatusDescription

FROM dbo.AuditLog AS AL WITH (NOLOCK)
cross apply Changeset.nodes('/root/ENCOUNTER.ENCOUTERSTATUSDESCRIPTION') AS t(b)


where
EntityTypeText ='Approved'
AND AuditActionTypeID =3
AND CreatedDate>='3/1/2013'
AND CustomerID=5862



I get back nothing but there should be data coming back.

The table schema is as follows
USE [KareoAudit]
GO

/****** Object: Table [dbo].[AuditLog] Script Date: 3/21/2013 3:56:48 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[AuditLog](
[AuditLogID] [bigint] IDENTITY(1,1) NOT NULL,
[Application] [varchar](50) NOT NULL,
[AuditActionTypeID] [int] NOT NULL,
[AuditTypeID] [int] NOT NULL,
[ChangeSet] [xml] NULL,
[EntityTypeId] [int] NOT NULL,
[EntityTypeText] [varchar](100) NULL,
[SubEntityTypeId] [int] NULL,
[SubEntityTypeText] [varchar](100) NULL,
[CustomerId] [int] NOT NULL,
[PracticeId] [int] NULL,
[UserId] [int] NOT NULL,
[UserName] [varchar](50) NOT NULL,
[CreatedDate] [datetime] NOT NULL,
CONSTRAINT [PK_AuditLog] PRIMARY KEY CLUSTERED
(
[AuditLogID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[AuditLog] WITH CHECK ADD CONSTRAINT [FK_AuditLog_AuditActionType] FOREIGN KEY([AuditActionTypeID])
REFERENCES [dbo].[AuditActionType] ([AuditActionTypeID])
GO

ALTER TABLE [dbo].[AuditLog] CHECK CONSTRAINT [FK_AuditLog_AuditActionType]
GO

ALTER TABLE [dbo].[AuditLog] WITH CHECK ADD CONSTRAINT [FK_AuditLog_AuditType] FOREIGN KEY([AuditTypeID])
REFERENCES [dbo].[AuditType] ([AuditTypeID])
GO

ALTER TABLE [dbo].[AuditLog] CHECK CONSTRAINT [FK_AuditLog_AuditType]
GO




Can anyone see any reason why I wouldn't get any results for this? I get data back when I just do a select from the auditlog table without parsing the xml.
Matt Miller (4)
Matt Miller (4)
SSC-Dedicated
SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)

Group: General Forum Members
Points: 30003 Visits: 19009
The short answer is "spelling counts". Your query is misspelling the node name you want. (i.e. couNter)

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
pamozer
pamozer
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1881 Visits: 443
Apparently I can't read. Can you please tell me what I have misspelled?
Matt Miller (4)
Matt Miller (4)
SSC-Dedicated
SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)SSC-Dedicated (30K reputation)

Group: General Forum Members
Points: 30003 Visits: 19009
Sorry - was running a bit short on time last night - update the spelling of ENCOUNTER in this line (the second one - where the underscores are):

cross apply Changeset.nodes('/root/ENCOUNTER.ENCOU___TERSTATUSDESCRIPTION')



You are missing the N.

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
pamozer
pamozer
SSCommitted
SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)SSCommitted (1.9K reputation)

Group: General Forum Members
Points: 1881 Visits: 443
Thank you so much. that was a good catch.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search