Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

XML query returning NULL values for the given query

$
0
0

Hi All,

I have an XML field in the  table like this and I am trying to read the values using the following query.

But the query returns NULL across the records. Please let me know where I am going wrong.

<root xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Header xmlns="http://schemas.datacontract.org/2004/07/ABC.Fabric.Services.Messages"><UserDeviceId>1</UserDeviceId><CorrelationId>71fb0504-d58f-4640-aecc-912100f7e85e</CorrelationId><DeviceId>SLATE_1</DeviceId><SentDateTime>2012-11-09T15:29:15.6040269+11:00</SentDateTime><ShiftId>1</ShiftId><UserName>UATUser</UserName></Header></root>

SELECT XMLMessage, XMLMessage.value('(./UserDeviceId/node())[1]', 'int') as CopsDeviceId, XMLMessage.value('(./CorrelationId/node())[1]', 'NVARCHAR(MAX)') as CorrelationId, XMLMessage.value('(./DeviceId/node())[1]', 'int') as DeviceId, XMLMessage.value('(./SentDateTime/node())[1]', 'DATETIME') as SentDateTime, XMLMessage.value('(./ShiftId/node())[1]', 'int') as ShiftId, XMLMessage.value('(./UserName/node())[1]', 'NVARCHAR(MAX)') as UserName FROM rollingLog

Thanks
M.Mahendra


Please click the 'Mark as Answer' button if my Reply helped you to solve your problem! Thanks M.Mahendra



Viewing all articles
Browse latest Browse all 23857

Trending Articles