title: SQL - Get specific element from an array
body: <p>Suppose I have 2 variables that look like an array:</p>
  
  <pre><code>declare @code nvarchar(200) = 
  ',10501,10203,10491,10490,10091,10253,10008,10020,10570,10499,';
  declare @value nvarchar(200) = 
  'True~~100000006~Digital~0~0~~1388.76~Completed~True';
  </code></pre>
  
  <p>I need to find if <code>@code</code> contains <code>10490</code> (for example) and if it does, I need to find a corresponding value (by its index) in <code>@value</code> variable which would be <code>Digital</code> since <code>10490</code> is the 4th element in <code>@code</code> array and 4th element of <code>@value</code> array is <code>Digital</code> (note that the 2nd element of the <code>@value</code> array is NULL.</p>
  
  <p><strong>Disclaimer</strong>:
  <code>@code</code> array will ALWAYS contain unique values. It's not possible to have more than 1 <code>10490</code> for example.
  <code>@code</code> array will always start and end with ','.
  Number of elements in <code>@code</code> and <code>@value</code> will always be the same if you take 1st and last comma off the <code>@code</code> variable.
  I cannot use functions or stored procedures, so everything needs to be done as part of 1 query.</p>