title: Pipe Separting inline in SQL
body: <p>Hi I am havin following data when execute my query</p>
  
  <p><a href="https://i.stack.imgur.com/cxBPQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cxBPQ.png" alt="enter image description here"></a></p>
  
  <p>I also have function which will pipe seprate Colum ReportType but it is writtening me column</p>
  
  <p>I want result in following format</p>
  
  <pre><code>ItemID |ReportType|EmailAddrress |FirstName|LastName
  1      |        1  |abc@gmail.com| test    |test 
  1      |        2  |abc@gmail.com| test1   |test1
  </code></pre>
  
  <p>My SQL function seems to be of no use  </p>
  
  <p>My function is </p>
  
  <pre><code>ALTER FUNCTION [dbo].[fnSplit](
      @sInputList VARCHAR(8000) -- List of delimited items
    , @sDelimiter VARCHAR(8000) = '|' -- delimiter that separates items
  ) RETURNS @List TABLE (item VARCHAR(8000))
  
  BEGIN
  DECLARE @sItem VARCHAR(8000)
  WHILE CHARINDEX(@sDelimiter,@sInputList,0) &lt;&gt; 0
   BEGIN
   SELECT
    @sItem=RTRIM(LTRIM(SUBSTRING(@sInputList,1,CHARINDEX(@sDelimiter,@sInputList,0)-1))),
    @sInputList=RTRIM(LTRIM(SUBSTRING(@sInputList,CHARINDEX(@sDelimiter,@sInputList,0)+LEN(@sDelimiter),LEN(@sInputList))))
  
   IF LEN(@sItem) &gt; 0
    INSERT INTO @List SELECT @sItem
   END
  
  IF LEN(@sInputList) &gt; 0
   INSERT INTO @List SELECT @sInputList -- Put the last item in
  RETURN
  END
  </code></pre>
  
  <p>select is normal query</p>
  
  <p>SELECT ItemId, ReportType, EmailAddress, FirstName, LastName<br>
  FROM EmailInfo</p>