Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server Case Count In Subquery Jelp?
    primarykey
    data
    text
    <p>There are many kinds of statusid in my table. Certain values mean that work in the table is "complete".</p> <p>If something is "complete", all of the statusid values for a grouped checkid are 1 or 10 or 40. Statusid values are not consecutive (there are many statusid values, this is just an extract). Can someone show how I can do an In Clause in a case subquery, or just a cleaner way to write this? </p> <p>Expected result set</p> <pre><code> checkid iscomplete 3 0 4 1 5 0 6 0 </code></pre> <p>4 is complete because there is only one row and it has a "10". 3 is not complete because one of the values is "1" but the others are "2". 5 is not complete because it only has "30" values. 6 is not complete because it has one "40" but it also has one "30".</p> <p>DML:</p> <pre><code>create table #test1 ( test1id int identity primary key , checkid int , statusid int ) insert into #test1 ( checkid , statusid ) values (3 , 1) insert into #test1 ( checkid , statusid ) values (3 , 2) insert into #test1 ( checkid , statusid ) values (3 , 2) insert into #test1 ( checkid , statusid ) values (4 , 10) insert into #test1 ( checkid , statusid ) values (5 , 30) insert into #test1 ( checkid , statusid ) values (5 , 30) insert into #test1 ( checkid , statusid ) values (6 , 30) insert into #test1 ( checkid , statusid ) values (6 , 40) select checkid , iscomplete = ( case when count(*) Where #test1.statusid In ( 1,10,40) Then 1 ) from #test1 group by checkid </code></pre> <p>Error:</p> <blockquote> <p>An expression of non-boolean type specified in a context where a condition is expected, near 'Where'.</p> </blockquote> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload