title: Insert values into table after splitting the string
body: <p>I want to insert values into employee table.
  And those values are in string format <code>~</code> separated</p>
  
  <p>E.g: <code>AA~B~123</code></p>
  
  <p>I am splitting it using following function </p>
  
  <pre><code>CREATE FUNCTION [db_owner].[FN_Split] (@String varchar(8000), @Delimiter char(1))
     returns @temptable TABLE (items varchar(8000))        
     as        
     begin        
         declare @idx int        
          declare @slice varchar(8000)        
  
          select @idx = 1        
              if len(@String)&lt;1 or @String is null  return        
  
         while @idx!= 0        
         begin        
             set @idx = charindex(@Delimiter,@String)        
             if @idx!=0        
                 set @slice = left(@String,@idx - 1)        
             else        
                set @slice = @String        
  
             if(len(@slice)&gt;0)   
                 insert into @temptable(Items) values(@slice)        
  
             set @String = right(@String,len(@String) - @idx)        
             if len(@String) = 0 break        
         end    
     return        
     end 
  </code></pre>
  
  <p>Now I get Output as</p>
  
  <pre><code>SELECT * FROM db_owner.FN_Split('AA~B~123','~')
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>items
  ______
  AA
  B
  123
  </code></pre>
  
  <p>Now I am stuck here</p>
  
  <p>How can I insert above values in employee table???</p>
  
  <p>like</p>
  
  <pre><code>insert into employee (name,add,phone)
  values('AA','B','123');
  </code></pre>
  
  <p>Please guide.</p>
  
  <p>Tried this but not working</p>
  
  <pre><code>insert into employee
  SELECT * FROM db_owner.FN_Split('AA~BB~CC','~')
  </code></pre>
  
  <p>ERROR</p>
  
  <pre><code>Msg 213, Level 16, State 1, Line 1
  Column name or number of supplied values does not match table definition.
  </code></pre>