Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
babloo
Starting Member
35 Posts |
Posted - 2014-05-07 : 10:06:17
|
Hi - I have a NTEXT field that stores HL7 data for ex:.MSH|^~\&|WORD|164|DADD|TEST|201404240936||ORU^R01||P|2.3 PID|..alot of HL7 then..OBR|||Specimen #PTA01-1|S^TEST|||I am trying to pull two items from the example above pull the word or value in the fifth position of '|' after MSH and pull the word or value in the fourth position of '|' after OBR.So I want something like this:TEST, S^TESTI tried Substring but that doesn't help much.Thank you. |
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-05-07 : 13:07:56
|
@s is your string. For whatever reason, I can't add a declare in my post right now.select Item from (select ROW_NUMBER() OVER(ORDER BY (SELECT 1)) as RowNumber, Item from dbo.Split(@s, '|')) twhere RowNumber = 6select Item from (select ROW_NUMBER() OVER(ORDER BY (SELECT 1)) as RowNumber, Item from dbo.Split(substring(@s, charindex('obr', @s), datalength(@s)), '|')) twhere RowNumber = 5Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
babloo
Starting Member
35 Posts |
Posted - 2014-05-07 : 14:01:41
|
Thanks tkizer |
|
|
|
|
|