A column in an app is being updated from storing a long string in a fixed-width column to a delimited column. Currently, there is one column that I write to a number of other columns based on the position by using substring()
.
Now that it is being updated to using a delimiter (~) to parse out each field within one column, I'm not sure how to extract the data and write them to individual fields in another table. Below is sample data and T-SQL:
Data
Radio $7.00~Shirt $79.99~Late Fee $9.95~Small Hat $7.00~Taxes $0.19
SQL:
INSERT INTO TempTable2 (Offer1, Offer2)
SELECT
SUBSTRING(OfferString, 1, 81) AS Offer1,
SUBSTRING(OfferString, 82, 81) AS Offer2
FROM
TempTable
In the fixed-width approach I could store each individual value to their own columns, per above, but not sure how to proceed with the new delimiter-based structure.
Can someone shed some light? Running on SQL Server 2008 R2.