Present it is working when the assigned values are static
DECLARE @str varchar(MAX)='45 | 00055 | 9/30/2016 | Vodafone | Randy Singh |Newyork | Test Msg | TBL101 | PC | 1.00 | COMP101 | CS | 1.00'
SELECT * FROM dbo.SUBSTRING_INDEX (@str,'|',7) (Function)
It is not working
DECLARE @str VARCHAR(1000)
SELECT @Str = [temp] FROM TempTable
It is selecting only last row value from table, I need to pass multiple value
How should I assign to @str as sql table resulted value here. Temp(column has many rows).
Function code.
alter FUNCTION dbo.SUBSTRING_INDEX_1
(
  @str NVARCHAR(4000),
  @delim NVARCHAR(1),
  @count INT
)RETURNS @rtnTable TABLE 
(
   HeaderData  NVARCHAR(2000),
   DetailData NVARCHAR(2000)
)
AS
BEGIN
    DECLARE @cnt INT=1;
    DECLARE @subStringPoint INT = 0
    WHILE @cnt <=@count
    BEGIN 
            SET @subStringPoint=CHARINDEX(@delim,@str,@subStringPoint)+1
            SET @cnt=@cnt+1
    END
    INSERT INTO @rtnTable
    SELECT SUBSTRING(@str,0,@subStringPoint-1)  ,SUBSTRING(@str,@subStringPoint+1,LEN(@str)) 
RETURN
END 
It is working
DECLARE @str varchar(MAX)='45 | 00055 | 9/30/2016 | Vodafone | Randy Singh |   Newyork | Test Msg | TBL101 | PC | 1.00 | COMP101 | CS | 1.00'
SELECT * FROM dbo.SUBSTRING_INDEX_1 (@str,'|',7)
It is not working
DECLARE @str TABLE (ObjectNames VARCHAR)
INSERT INTO @str
SELECT o.temp FROM OMSOrderTemp o
SELECT * FROM @str
SELECT * FROM dbo.SUBSTRING_INDEX_1(@str, N'|', 7)
 
    