SP for splitting and storing values in TEMP Table

Self-Innovator
Posted by Self-Innovator under Sql Server category on | Points: 40 | Views : 832
ALTER PROC sp_SplitVal
AS
BEGIN
DECLARE @Test VARCHAR(1000), @RecSet VARCHAR(500),@StartingPos INT,@RecPos INT
DECLARE @temptable TABLE(COMPLEXIONID INT)
SET @StartingPos= 1
SET @TEST='1,3,4,'
WHILE @StartingPos<=LEN(@Test)
BEGIN
SELECT @RecPos = CHARINDEX(',',@Test,@StartingPos)
SET @RecSet=SUBSTRING(@Test,@StartingPos,@RecPos-@StartingPos)
PRINT @RecSet
BEGIN
INSERT INTO @temptable VALUES(@RecSet)
SELECT @StartingPos=@RecPos+1
END
END
SELECT * FROM @temptable
END


Run the below statement to see the output
EXEC sp_SplitVal

Comments or Responses

Login to post response