title: Subquery returned more than 1 value. with where clause in SQL Server 2012
body: <p>I have a stored procedure in which I pass a comma-separated id, I use this in <code>where</code> clause with case statement with 'IN'.</p>
  
  <p>I get this error :</p>
  
  <blockquote>
    <p>'Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, &lt;, &lt;= , >, >= or when the subquery is used as an expression.'</p>
  </blockquote>
  
  <p>My procedure is </p>
  
  <pre><code>ALTER Proc [dbo].[proc_generatdetail]
      @TagIds varchar(1000)
      @IsMinStock bit,
      @Tags varchar(1000)
  AS
  BEGIN
      SELECT
          IMd.ItemCode, I.ITEM_No 
      FROM
          Item I
      LEFT JOIN 
          tblItemSize ITS ON I.ITEMCode = ITS.ItemId 
                          AND I.BranchId = ITS.BranchId           
      WHERE  
          CASE 
             WHEN @Tags IS NOT null  
                THEN ITS.SizeId 
             ELSE 1 END IN 
                  (case when @Tags is not null then (select id from CSVToTable(@TagIds)) else (1) end)
  
  END
  </code></pre>
  
  <p><code>CSVToTabes</code> returs table of ids, and I don't have to use if - else condition. 
  So please give solution for this if anyone have.</p>