Solved

How to query a CLOB field

Posted on 2008-10-02
5
248 Views
Last Modified: 2011-10-19
Hi.  I have a piece of code that downloads a Clob field into a table and then I parse out the node that I need from the field.  The problem is that there are several nodes that have the same name and I need to be able to filter by the attribute.  I have attached my code as well as a snapshot of what the node tree looks like.  The name of the nodes are all called "item" but they are all have different attribute types.  I am looking for attribute name =  'Type'  and attribute value =  "TX_SALE" but I don't know how to write this in the where statement.  I have selected the first node in my where statement by default but this isn't returning all my data.  I need to be able to filter by attribute.  Can someone help me?
INSERT into #WorkingDataset
SELECT
	CAST(xmlsrc.SITE_NO as Integer)			SITE_NO,
	CAST(xmlsrc.TRAN_DT as DateTime)		TRAN_DT, 
	CAST(xmlsrc.REG_NO as Integer)			REG_NO,
	CAST(xmlsrc.TRAN_NO as Integer)			TRAN_NO,
	CAST(xmlsrc.XML_PENDING as CHAR(1))		XML_Status,
	CAST(xmlsrc.XML_DATA as XML) 			XML_DATA
	
FROM
	[TOMAX_PROD]..[TMX].[TX_STAGING] xmlsrc
	
-----------------------------------------------------------
-- Now that we converted this to xml data we can use,
-- we need to return everything that has a reason_code
-----------------------------------------------------------
SELECT
	Site_No,
	Tran_dt,
	Reg_no,
	Tran_No,
	XML_Status,
	nref.value('itemno[1]', 'VarChar(12)') SKUCode,
	nref.value('quantity[1]', 'Integer') QuantitySold,
	nref.value('reason_code[1]/qty[1]', 'Integer') qty
INTO #ReturnResults	
FROM   
	#WorkingDataset CROSS APPLY XML_Data.nodes('/transaction/item') AS R(nref)
WHERE
	LEN(nref.value('itemno[1]', 'VarChar(12)')) = 6
	
ORDER BY
	Site_No,
	Tran_dt,
	Reg_no,
	Tran_No

Open in new window

0
Comment
Question by:skielark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 51

Assisted Solution

by:Mark Wills
Mark Wills earned 60 total points
ID: 22643553
Can you the XML source data ? just a few... Think you are missing that snapshot as well...
0
 

Author Comment

by:skielark
ID: 22647033
I don't even understand the question.  Can you the XML source data?  What does that mean.
0
 
LVL 51

Assisted Solution

by:Mark Wills
Mark Wills earned 60 total points
ID: 22648941
Yeah - I am having a hard time understanding it myself ...

CLOB returns the contents as a single-row, single-column rowset of type varchar(max), so you may have to use some of the XML facilities.

Can you post a few lines of of your source data... and how you are loading it ?

You mentioned a snapshot that you were attaching, but didn't see it...
0
 
LVL 51

Assisted Solution

by:Mark Wills
Mark Wills earned 60 total points
ID: 22648944
Also, what versions of SQL are you using...
0
 

Accepted Solution

by:
skielark earned 0 total points
ID: 22651820
Mark, I can use either SQL server 2000 or 2005.  I attached the screenshot of the source data with the nodes.
Attribute.doc
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
StoredProcedure to JSON query faulty syntax 2 45
calculate days away 11 62
T-SQL: Wrong Result 7 39
DMV Script to find how many times statistics are utilized 2 30
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question