title: Query only takes the first value of subquery
body: <p>I am creating an SQL function to report, the parameters I receive are several strings containing the PK separated by <code>,</code> example:</p>
  <pre><code>@ID_Model_list = '1,2'
  @ID_Station_list = '1,4,7,8,10'
  </code></pre>
  <p>in my SQL query I perform a subquery, with it I convert the variables I receive into a column, example:</p>
  <pre><code>SELECT CAST(VALUE AS INT) AS ID FROM string_split(@ID_Model_list,',')
  </code></pre>
  <p>would be the same as: <code>SELECT CAST(value AS int) AS ID FROM string_split('1,2',',')</code></p>
  <p>Result:</p>
  <p><a href="https://i.stack.imgur.com/oqDt4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oqDt4.png" alt="enter image description here" /></a></p>
  <p>If I add the code above to my query, it only takes the first value of the column that results from the subquery</p>
  <pre><code>CREATE FUNCTION V_Scrap_Report
   (@ID_Model_list varchar, @ID_Station_list varchar, @fecha datetime, @fechafin datetime)
   RETURNS TABLE
   AS RETURN
  (SELECT   S.IDScrap
          , S.fecha
          , M.modelo
          , E.estacion 
          , C.correccion
          , S.elemento
          , P.nombre
          , P.numeroparte
          , Sp.cantidad
  FROM            dbo.Scrap           S 
  FULL OUTER JOIN dbo.Modelo          M   ON  S.IDModelo      =   M.IDModelo
  FULL OUTER JOIN dbo.Estacion        E   ON  E.IDEstacion    =   S.IDEstacion
  FULL OUTER JOIN dbo.Scrapcorreccion Sc  ON  S.IDScrap       =   Sc.IDScrap
  FULL OUTER JOIN dbo.Correccion      C   ON  C.IDCorrecion   =   Sc.IDCorrecion 
  FULL OUTER JOIN dbo.Scraparte       Sp  ON  S.IDScrap       =   Sp.IDScrap
  JOIN        dbo.Parte           P   ON  Sp.IDParte      =   P.IDParte 
  WHERE S.fecha   &gt;= @fecha 
  AND   S.fecha   &lt;= DATEADD(HOUR,23.9999,@fechafin)
  AND   S.IDModelo = (SELECT CAST(VALUE AS INT) AS ID FROM string_split(@ID_Model_list,','))
  AND   S.IDEstacion = (SELECT VALUE FROM string_split(@ID_Station_list,',')))
  </code></pre>
  <p>The above function is only returning results when <code>S.IDModelo = 1</code> <code>AND</code> <code>S.IDEstacion = 1</code> does not take into account that there is:</p>
  <p><code>S.IDModelo = 2 AND S.IDEstacion = 1</code></p>
  <p><code>S.IDModelo = 1 AND S.IDEstacion = 4</code></p>
  <p><code>S.IDModelo = 1 AND S.IDEstacion = 7</code></p>
  <p><code>S.IDModelo = 1 AND S.IDEstacion = 8</code></p>
  <p><code>S.IDModelo = 2 AND S.IDEstacion = 10</code></p>
  <p>When I call the function I do it like this:</p>
  <pre><code>SELECT * FROM V_Scrap_Report('1,2','1,4,7,8,10','2022-07-18','2022-07-20')
  </code></pre>
  <p><strong>oddish</strong>, if i change <code>... V_Scrap_Report('1,2'...</code> by <code>... V_Scrap_Report('2,1'...</code> just bring</p>
  <p><code>S.IDModelo = 2 AND S.IDEstacion = 1</code></p>
  <p>what could be missing in the query so as not to skip matches?</p>