title: SQL Substring and Charindex
body: <p>I have 111-1001-0000-0000 this record in one column and 453200-0000-000 in second column</p>
  <p>I want output as 111-1001-0000-453200-0000-0000-000</p>
  <p>That means 111-1001-0000 from 1st column and 453200 from 2nd column and again 0000 from 1st column and 0000-000
  from 2nd column</p>
  <p>I tried below query but getting 111-1001-453200-0000-0000-000.</p>
  <p>-0000 is missing from 1st column</p>
  <pre><code>Declare @1stcolumn nvarchar(30),@2ndcolumn nvarchar(30)
  
  set @1stcolumn='111-1001-0000-0000'
              
  set @2ndcolumn='453200-0000-000' 
  
  select substring(@1stcolumn,1,charindex(right(@1stcolumn,charindex('-',reverse(@1stcolumn))),@1stcolumn))
  +substring(@2ndcolumn,1,charindex('-',@2ndcolumn))+reverse(substring(reverse(@1stcolumn),0,charindex('-',reverse(@1stcolumn))))
  +'-'+substring(@2ndcolumn,charindex('-',@2ndcolumn)+1,len(@2ndcolumn)) 
  </code></pre>