title: Reverse order of every other character in a string
body: <p>I'm currently working on a project where the data I'm receiving is being given to me in a messed up order. I need every 2 characters to switch places in a string. Currently I have the below code, but it is ungodly slow in a function or stored procedure. Any help would be appreciated. </p>
  
  <p>Ex: <code>FK741 OCEV</code> needs to be <code>KF47 1COVE</code></p>
  
  <pre><code>ALTER FUNCTION [dbo].[UnscrambleData] 
  (
      @scrambled varchar(50) 
  )
  RETURNS varchar(50)
  AS
  BEGIN
      Declare @unscrambled varchar(50)
      Declare @temp1 varchar(1)
      DECLARE @cnt INT = 0;
      Declare @cnt_Total INT =len(@scrambled)
  
      WHILE @cnt &lt; = @cnt_total
         if((@cnt%2)=0)
         begin 
               set @unscrambled=CONCAT( @unscrambled,SUBSTRING(@scrambled, @cnt, 1),@temp1)
               set @temp1=''
         end
     else if (@cnt_Total%2&lt;&gt;0 and @cnt_Total-@cnt&lt;2)
         begin
                set @unscrambled=CONCAT( @unscrambled,SUBSTRING(@scrambled, @cnt, 1))
         end
     else
         begin
               set @temp1= SUBSTRING(@scrambled, @cnt, 1)
         end
     SET @cnt = @cnt + 1;
  
      RETURN @unscrambled;
  END
  </code></pre>