1

Consider a column in an MS SQL database which will house either potentially large chunks or XML or pipe-delimited HL7v2 data.

Currently (due to not using forward-thinking) it's currently typed as XML because originally we were only ever accepting XML data. While technically this could work, it means that all the XML special characters in the HL7v2 messages are being encoded (& --> & etc.).

This is not ideal for what we are doing. If I were to convert this column to a different datatype, what would be recommended? I was thinking nvarchar(max) as it seems like it would handle it, but I'm not well-versed in SQL datatypes and the implications of using different types for such data.

Bensonius
  • 1,501
  • 1
  • 15
  • 39

3 Answers3

3

There really isn't much of a choice other than nvarchar(max).

The other options are either varchar(max) or varbinary(max). You might need Unicode so you can't use varchar. It would work to store it as varbinary, but it would just be annoying to work with.

David
  • 34,223
  • 3
  • 62
  • 80
  • Thanks. I guess my thoughts weren't that far off then. The only reason I asked is someone here suggested `varbinary(max)` over `nvarchar(max)` but everything I looked into for `varbinary` meant it would mean converting the data to something non-binary just to work with it the way we want to. – Bensonius Feb 19 '16 at 21:22
1

Use HAPI to transform the HL7 messages from ER7 (pipe delimited) to XML encoding. That way you can use a single SQL Server XML column for everything. And it will give you the added benefit of being able to query into HL7 message contents using XQuery.

Nick Radov
  • 401
  • 2
  • 7
-1

As Nicks say, converting pipe delimited to XML and then persist in XML is the best option, trying to persist xml and pipe delimited values in a same column for me it make no sense, as on source they are different data types.

Marti Pàmies Solà
  • 611
  • 1
  • 6
  • 12