Step 1. Create a String_Split function. Please follow this link for various options.
Go
CREATE FUNCTION [dbo].[string_split](
@delimited NVARCHAR(MAX),
@delimiter NVARCHAR(100)
) RETURNS @t TABLE (id INT IDENTITY(1,1), val NVARCHAR(MAX))
AS
BEGIN
DECLARE @xml XML
SET @xml = N'<t>' + REPLACE(@delimited,@delimiter,'</t><t>') + '</t>'
INSERT INTO @t(val)
SELECT r.value('.','varchar(MAX)') as item
FROM @xml.nodes('/t') as records(r)
RETURN
END
GO
Step 2. Compose the INSERT queries from your data as below. I have used a temp table here, you can easily replace it with your actual table. Please note I did not replace spaces from your @data
(you can adjust this SQL as per your needs).
go
CREATE TABLE #target_table (A VARCHAR(100), B INT, C INT);
DECLARE @temp TABLE (q varchar(max));
DECLARE @data varchar(max)='col1 ~ 100 ~ 200 | col2 ~ 700 ~ 800 | col3 ~ 180 ~ 800' ;
DECLARE @inserts varchar(max)='';
INSERT INTO @temp
SELECT 'SELECT ''' + REPLACE(val, '~', ''',''') +'''' from dbo.string_split(@data, '|');
SELECT @inserts = @inserts + CHAR(13) + CHAR(10) + q + ' UNION ALL '
FROM @temp
SELECT @inserts = 'INSERT INTO #target_table(A, B, C) ' + @inserts
SELECT @inserts = SUBSTRING(@inserts, 1, LEN(@inserts) - LEN(' UNION ALL'))
--print(@inserts)
EXEC(@inserts)
SELECT * FROM #target_table
If you do not wish to change the #target_table in the above SQL, you could write a SELECT INTO query at the end.
INSERT INTO <Your_Actual_Target_Table>(cols...)
SELECT cols...
FROM #target_table
Note: Please remember to replace any single quotes within the @data with two single quotes, an error will be produced otherwise.