My query is like below.I want to select values if Type = 1 and subtype = 1,3 or 2.
select sum(case when Type = 1 and SubType in (1, 3 or 2) then 1 else 0 end) as 'WorkStations'
Is this right way?
My query is like below.I want to select values if Type = 1 and subtype = 1,3 or 2.
select sum(case when Type = 1 and SubType in (1, 3 or 2) then 1 else 0 end) as 'WorkStations'
Is this right way?
Try avoiding
IN
Predicates and instead use Joins because it Iterate unnecessarily despite of the fact that there is just one/two match. I will explain it with an example.Suppose I have two list objects.
Using
IN
, it will search for each List-1 item in List-2 that means iteration will happen 49 times !!!If you're simply counting records, your best bet is to use the COUNT function provided by SQL Server. Consider using the following:
It is best to avoid using 'IN' as it can lead to unnecessary calls to the SQL engine.
Since you're only trying to get a count of the workstations that meet the criteria as far as I can see:
Also, an IN clause is by nature already an OR. It is neither valid syntax nor necessary to state it.