I do not quite understand why these two different codes return a different value.
incorrect, but working syntax returns false results, for example, it returns 0 when the comparison is performed on two equal values:
(SELECT CASE WHEN SUM(V.IsCompatible) OVER (PARTITION BY ComputerName, UserID) = ApplicationCount THEN 1 ELSE 0 END ) AS CompatibleUser
The following are the correct values , i.e. 1 when two equal values ββare compared.
(CASE WHEN SUM(V.IsCompatible) OVER (PARTITION BY ComputerName, UserID) = ApplicationCount THEN 1 ELSE 0 END ) AS CompatibleUser
or even simpler:
(SELECT CASE WHEN X = Y THEN 1 ELSE 0 END ) AS Result
X = 22 And Y = 22 => Result = 0
(CASE WHEN X = Y THEN 1 ELSE 0 END ) AS Result
X = 22 And Y = 22 => Result = 1
I understand that the correct syntax is applied , and I know the syntax of SELECT CASE in T-SQL, but I do not understand how the sample of the first code is evaluated and bring an unexpected result.
update: full request in context
select userapplication.username, computerdetails.computername, sum(userapplication.iscompatible) over (partition by computerdetails.computername, userapplication.userid) as compatiblecount, userapplication.applicationcount, ( case when sum(userapplication.iscompatible) over (partition by computerdetails.computername, userapplication.userid) <> userapplication.applicationcount then 0 else 1 end ) as usercomputeriscompatible from computerdetails right outer join usercomputer on computerdetails.computerid = usercomputer.computerid right outer join userapplication on usercomputer.gebruikerid = userapplication.userid
so userComputerIsCompatible is the result we are talking about here.