Skip to content
Advertisement

How to Split 2 Strings and insert in to 2 columns

I have 2 strings

I need to split these 2 string and insert into a table

Example at 07:00:0:0=>1.00 1:00:1:0=>2.00

I have taken a table and split and inserted my when details

enter image description here

How can fill the dosage column as shown in the example?

Note I might have n number of records to split I have given these just an example.

Advertisement

Answer

Perhaps with a little JSON (assuming 2016+)

Example

Returns

If it helps with the Visualization:

We convert the strings into a JSON array, then it is a small matter to join the results based on the KEY

If you were to

Select * From OpenJSON( '["'+replace(@WhenDetails,';','","')+'"]' )

The results would be

EDIT – XML Approach

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement