title: How to insert a comma separated values to the column to a SQL table in a order same as passing order?
body: <p>i written a code like below to insert a comma separated values to the tempTble.It is working but i need the values to be entered in a order same as am passing it to query.But here number are arranged in a numerical order and string values arranged according to alphabetical order .Example '7,6,5,1,2,Jack,Ana,Micky' but it is inserted to column in a order of '1,2,5,6,7,Ana,Jack,Micky'. </p>
  
  <p>Can you please provide answer for this.
  Thank you in advance</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[usp_GetValuesFromBillingSystem]
  (
  @BillingSystemCode VARCHAR(max)
  ) 
  AS
  BEGIN
  DECLARE @planID varchar(max) = Null ;
  
  SET @planID= @BillingSystemCode
  DECLARE @tempTble Table (planID varchar(50) NULL);
  while len(@planID ) &gt; 0
  begin
  insert into @tempTble (planID ) values(left(@planID , charindex(',', @planID +',')-1))
  set @planID = stuff(@planID , 1, charindex(',', @planID +','), '')
  end
  select * from @tempTble 
  
  END 
  </code></pre>