Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Statement

Posted on 2014-09-30
6
Medium Priority
?
136 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 49

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 26

Expert Comment

by:Tomas Helgi Johannsson
ID: 40352484
0
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 1500 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

885 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