First create a function to divide your string into separate values:
CREATE FUNCTION dbo.splitstring ( @separador CHAR, @stringToSplit VARCHAR(MAX) )
RETURNS
@returnList TABLE ([Name] [nvarchar] (500))
AS
BEGIN
DECLARE @name NVARCHAR(255)
DECLARE @pos INT
WHILE CHARINDEX(@separador, @stringToSplit) > 0
BEGIN
SELECT @pos = CHARINDEX(@separador, @stringToSplit)
SELECT @name = SUBSTRING(@stringToSplit, 1, @pos-1)
INSERT INTO @returnList
SELECT @name
SELECT @stringToSplit = SUBSTRING(@stringToSplit, @pos+1, LEN(@stringToSplit)-@pos)
END
INSERT INTO @returnList
SELECT @stringToSplit
RETURN
END
Call the created function by passing a string containing the values separated by "!":
SELECT * FROM dbo.splitstring('!', '91!12!65!78!56!789')
The result for this query will be as below:
Toinsertthevaluesinyourothertable,simplyadaptthefollowingcommandaccordingtothecolumnsyouhaveinyourtable:
INSERTINTOTabelaDeDestinoSELECTNameFROMdbo.splitstring('!','91!12!65!78!56!789')
ThisisanadaptationoftheEnglishresponse link