That's more or less what I was saying in my last post, except it will be easier for me to do it in Delphi than in SQL Server. This is partly because the existing import code is written in Delphi, and partly because I'm much more fluent in Delphi than I am in SQL.
I admit I hadn't realised SQL Server could even do that - it constantly amazes me what is possible. However, SQL code to do anything much out of the ordinary always appears to me to be byzantine in its obscurity and complexity, so I keep the SQL simple and confined to just the business of storing and retrieving the data, and do the general purpose stuff in a language that is better suited to it
.
Rgds, Andy