title: Error when trying to store function result to a variable using stored procedure
body: <p>I'm trying to create a stored procedure or a trigger in which it will store the function result inside a variable and insert it to a table.</p>
  
  <p>Here's my function which parse raw data</p>
  
  <pre><code> ALTER FUNCTION [dbo].[ufn_Parserstring] 
      (@StringInput VARCHAR(max))
   RETURNS @OutputTable TABLE ([String] VARCHAR(max))
   AS
   BEGIN
        DECLARE @String    VARCHAR(max)
  
        WHILE LEN(@StringInput) &gt; 0
        BEGIN
           SET @String = LEFT(@StringInput, 
                              ISNULL(NULLIF(CHARINDEX(',', @StringInput) - 1, -1),
                              LEN(@StringInput)))
           SET @StringInput = SUBSTRING(@StringInput,
                                        ISNULL(NULLIF(CHARINDEX(',', @StringInput), 0),
                                        LEN(@StringInput)) + 1, LEN(@StringInput))
  
           INSERT INTO @OutputTable ([String])
           VALUES (@String)
        END
  
        RETURN
   END
  </code></pre>
  
  <p>After it parses the raw data I will call the results using the stored procedure which stores the result inside a variable</p>
  
  <p>Here's the stored procedure I'm trying to do</p>
  
  <p>Kindly advice if wrong or not</p>
  
  <pre><code>declare @str2 varchar(max)
  declare @account varchar(max)
  declare @GPS varchar(max)
  
  set @str2  = (SELECT TOP 1 smsmsg FROM GPRSIN)
  
  set @account = (SELECT TOP 2 * 
                  FROM 
                     (SELECT 
                         String, ROW_NUMBER() OVER (ORDER BY String desc) AS Rownumber
                      FROM [dbo].[ufn_Parserstring] ( replace(@str2,';',','))) results
                  WHERE results.Rownumber = 2)
  
  set @GPS = (SELECT TOP 1 * 
              FROM 
                  (SELECT 
                       String, ROW_NUMBER() OVER (ORDER BY String desc) AS Rownumber
                  FROM [dbo].[ufn_Parserstring] (replace(@str2,';',','))) results
              WHERE results.Rownumber = 1)
  </code></pre>
  
  <p>Whenever I try running this I get this error</p>
  
  <blockquote>
    <p>Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.</p>
  </blockquote>
  
  <p>If you need the flow then here's the flow</p>
  
  <pre><code>351856040489593
  241111
   1R
   141119040115
   A
   1422.1425N
  12103.1746E
  0.0
  151
  1.8
  01000006
  </code></pre>
  
  <p>rawdata -> parse by the function parser which give a result like the one above. -> the SP im trying to do will store the query result to variable -> insert the value of variables to a certain table (for example tblblablabla)</p>
  
  <p>Kindly help me guys.</p>
  
  <p>Thanks.</p>