I'm new to cursors,
How should I write my below code in cursor to pass column value to variable @str
Basically @str in below code is taking static value, need to pass table column values
DECLARE @str VARCHAR(1000),
@str1 VARCHAR(1000),
@str2 VARCHAR(1000),
@pos INT,
@counter INT
SET @str = '45 | 00055 | 9/30/2016 | Vodafone | Randy Singh | Newyork | Test Msg | TBL101 | PC | 1.00 | COMP101 | CS | 1.00.............. etc'
(Here i need to pass table column value like--- select name from Order so every time it takes new value)
--select @str = temp FROM OrderTemp
SET @counter = 0
SET @pos = 0
WHILE @counter <= 6
BEGIN
SET @pos = CHARINDEX('|', @str, @pos + 1)
SET @counter = @counter + 1
END
SET @str1 = SUBSTRING(@str, 1, @pos)
SET @str2 = SUBSTRING(@str, @pos+1, LEN(@str)-@pos)
insert into OrderInterface (name)(SELECT @str2)
insert into OrderInterface (Id)(SELECT @str1)
Input
@str :-- '45 | 00055 | 9/30/2016 | Vodafone | Randy Singh | Newyork | Test Msg | TBL101 | PC | 1.00 | COMP101 | CS | 1.00.............. etc'
Now i need to pass Input value from table like : Select name from tablename instead of static values.
Ouput
@str1 :-- '45 | 00055 | 9/30/2016 | Vodafone | Randy Singh | Newyork | Test Msg'
@str2 :-- 'TBL101 | PC | 1.00 | COMP101 | CS | 1.00.............. etc'

