I need to split a string in sql server and insert the data in a table.
Te string is fixed length, no comma separated. In the string I can have 1 or more records to insert, for example:
id = 2 characters
name = 4 characters
string: 01AAAA02BBBB03CCCC.
In this example I have 3 records to insert (I can have only one record or more in the string)
id Name
01 AAAA
02 BBBB
03 CCCC
I need a way to split this info in two different columns and in three different rows. I was thinking to use BCP utility but I’m not sure, maybe I need to split and generate a file and then use BCP.
Any idea?
The following will handle more than 3 id/name pairs. Note however, that there is no error checking. I leave that to you.