Solved

SQL Statement

Posted on 2014-09-30
6
130 Views
Last Modified: 2014-12-15
Hi All,

I  have a large database with a collumn called RegDataXml which has around 50 lines of XML within it.

Within this large XML are 2 tags <frn> 218 805 </frn> which i need the query to return.

HOWEVER, Following this, i would ONLY like to return the FRN numbers which ARE ABOVE 100 000, Can any one assist me?

Many thanks,

Richard
0
Comment
Question by:Richiep86
6 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40351748
well you have not helped by choosing 3 different databases...

the syntax for retrieving XML is different in Oracle to MS SQL Server (and I presume MySQL will also be different)

Please, which database is it? (and what version, it may make a difference)
0
 

Author Comment

by:Richiep86
ID: 40351829
Apologies, its Microsoft SQL.

Thanks for your prompt response,
0
 

Author Comment

by:Richiep86
ID: 40351832
MS SQL Server 2005
0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 40352484
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 40355439
If "<frn>" will appear only once (or none) in the column, you could also convert the xml to varchar and use CHARINDEX().  For example:


SELECT frn_value, ...
FROM table_name
CROSS APPLY (
    SELECT CAST(RegDataXml AS varchar(max)) AS RegDataVarchar
) AS assign_aliases_1
CROSS APPLY (
    SELECT CHARINDEX('<frn>', RegDataVarchar) AS RegData_start_of_frn
) AS assign_aliases_2
CROSS APPLY (
    SELECT LTRIM(RTRIM(CASE WHEN RegData_start_of_frn = 0
        THEN ''
        ELSE SUBSTRING(RegDataVarchar, RegData_start_of_frn + 5, CHARINDEX('</frn>', RegDataVarchar) - RegData_start_of_frn)
        END)) AS frn_value
) AS assign_aliases_3
WHERE
    frn_value >= '100 000'
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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

713 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