473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XML data in SQL Server

Hi there

I am attempting to extract xml data out of a table on a SQL Server database. The xml is stored in a table column as a text value. The data is stored like this in the coulmn:

<DATA>

<SERVICE_9_ID>1234567</SERVICE_9_ID>

<SERVICE_9_TEAM lookup="1">TEAM_POT</SERVICE_9_TEAM>

<SERVICE_9_STAFF lookup="1">MACDONALD</SERVICE_9_STAFF >

<SERVICE_9_ TEAM lookup="1">TEAM_PHYSIO</SERVICE_9_STAFF_TEAM>

<SERVICE_9_ TEAM lookup="1">TEAM_DDT</SERVICE_9_STAFF_TEAM>

<SERVICE_9_ TEAM lookup="1">TEAM_DCC</SERVICE_9_STAFF_TEAM>

<SERVICE_9_STAFF lookup="1">MCLELLAN</SERVICE_9_STAFF>

<SERVICE_9_STAFF lookup="1">WILKINS</SERVICE_9_STAFF>

<SERVICE_9_STAFF lookup="1">SAVAGE</SERVICE_9_STAFF>

</DATA>

Currently I am treating the xml as a large string and stripping out the data I want using substring and charindex's as there are tag names that repeat. I use the charindex's to dictate where the next substring is to start so I can get the second, third, and fourth instances of each of these tags. As you can imagine, my query is comically large, almost 800 lines. Using this technique I am getting the desired results, but the size of the query is makes it very cumbersome and difficult to manage.

This is some of the code I am using, just so you know where I'm at:

SELECT
SUBSTRING(
test.dbo.idifd_form.xmlFormData,
CHARINDEX(
'>',
test.dbo.idifd_form.xmlFormData,
CHARINDEX(
'ID',
test.dbo.idifd_form.xmlFormData
)
)+1,
CHARINDEX(
'<',
test.dbo.idifd_form.xmlFormData,
CHARINDEX(
'ID',
test.dbo.idifd_form.xmlFormData
)
)
- CHARINDEX(
'>',
test.dbo.idifd_form.xmlFormData,
CHARINDEX(
'ID',
test.dbo.idifd_form.xmlFormData
)
)-1
) AS ID,

SUBSTRING(
test.dbo.idifd_form.xmlFormData,
CHARINDEX(
'>',
test.dbo.idifd_form.xmlFormData,
CHARINDEX(
'TEAM',
test.dbo.idifd_form.xmlFormData
)
)+1,
CHARINDEX(
'<',
test.dbo.idifd_form.xmlFormData,
CHARINDEX(
'TEAM',
test.dbo.idifd_form.xmlFormData
)
)
- CHARINDEX(
'>',
test.dbo.idifd_form.xmlFormData,
CHARINDEX(
'TEAM',
test.dbo.idifd_form.xmlFormData
)
)-1
) AS TEAM, ...

This goes on, and on, and on...

Does anyone know of a technique in MS SQL Server 2000/2005 which can extract this data any easier than a giant substring query? I am reasonably inexperienced with SQL Server and any help will be much appreciated.
Sep 25 '07 #1
1 1404
debasisdas
8,127 Expert 4TB
As you have posted a question in the articles section it is being moved to SQL Server Forum.

MODERATOR.
Sep 25 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Philip Trim | last post by:
General Brief: 3 SQL Servers as MS SQL Server 2000 Standard Edition with Service Pack 3 All using FTP for snapshots All Servers are both Publishers and Distributors. Server A has the correct...
2
by: Serdar Yegulalp | last post by:
I'm in the process of migrating a lot of data (millions of rows, 4GB+ of data) from an older SQL Server 7.0 database to a new SQL Server 2000 machine. Time is not of the essence; my main concern...
32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
0
by: Alex | last post by:
Interested in more .NET stuff visit www.dedicatedsolutions.co.uk The DataList is not as powerful as the DataGrid. It requires more work from you since it has no default data presentation format....
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
9
by: David Harris | last post by:
Ok, so I'm semi-new to .NET, having done everything manually with SQL code back in VB6. So before I program this up completely manually again, I thought I'd ask for better ways to think through...
17
by: Timothy.Rybak | last post by:
Hello all, This is my first attempt at an application, so kid gloves are appreciated. I need to make a very simple form that only has a few elements. One is TraceCode - a text field that is...
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
7
ADezii
by: ADezii | last post by:
There are essentially three techniques for publishing Access Data on the Web. The first technique is static, and does not allow for the dynamic addition or modification to the data, There is no...
1
by: starter08 | last post by:
Hi, I have a C++ routine(client-side) which uploads an xml file to a web server by making a socket connection and sending all the post request through that socket. On the server side I have a cgi...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.