Blogs Home
Monday, December 5, 2016 1:00 PM

SQL Tip: How to Strip Repeating Delimiters from String

Written by Thomas Harlan, Jim McGrath; Reporting Services Team - iatricSystems

This is a small tip, but could be quite useful on the days you need it.

Particularly when you work with MEDITECH 6.x PCS data, you will often encounter query response values that look like this:

{|||,30+3/40 Emergency|||||LSCS|Apgar 4/1 7/5}

You can use IatricPiece() to pick out chunks of the delimited data, but you might find too many extra delimiters in place, particularly leading delimiters. So you want to process the string first, to take those out.

Thus IatricStripRepeats()!

Which converts the above string example, via this code:

DECLARE @char char(1) = '|' ;
DECLARE @str varchar(max) = '{|||,30+3/40
Emergency|||||LSCS|Apgar 4/1 7/5}' ;

SELECT zcus.dbo.IatricStripRepeats( @char,@str );

Into...

{|,30+3/40 Emergency|LSCS|Apgar 4/1 7/5}

Which is starting to get you somewhere.

If you need more help…

Our Report Writing team can help you fix reports, create new ones, make old ones faster, and much more. Simply reach out to your Iatric Systems Account Executive or our NPR report writing team at reportwriting@iatric.com to discuss how we can help support your team!

RW-HELP-Button-Blue.png