I have a string with values:
@value = 'e65.89,f34.yy,sw21.67,aqw21,g45.g4'
I need to insert this string as individual rows into a temporary table.
like:
VALUES
e65.89
f34.yy
sw21.67
aqw21
g45.g4
I Tried this code,it works fine with integer values but when a float or varchar value is given it shows error:
code:
CREATE TABLE #Temp (SNo INT IDENTITY(1,1),Code VARCHAR(max))
Declare @value varchar(max)
set @value = 'e65.89,f34.yy,sw21.67,aqw21,g45.g4'
DECLARE @InsertStatement varchar(max) = 'insert into #Temp values ('+REPLACE(@value ,',','),(')+');';
EXEC (@InsertStatement);
SELECT * FROM #Temp;
Error:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'e'.