I inherited some code from a coworker and I noticed that the way that some of the code is not consistent
For example, is ther any functional difference between the following:
sum(case when (elephants = 0)then 1 else 0 end),
sum(case when (elephants = '0')then 1 else 0 end),
sum(case when (elephants IN (0))then 1 else 0 end),
sum(case when (elephants IN ('0'))then 1 else 0 end);
If there isn’t a functional difference between using single qutoes or IN vs = when looking for a single value, what other reason could account for it (other than sloppy code)?
x IN (a, b, c)meansx = a OR x = b OR x = c. When theINlist contains a single item,x IN (a)just meansx = a.As for the difference between
0and'0', the former is an integer, the latter is a character string. The latter can be converted to an integer, so whenelephantsis an integer too,elephants = 0andelephants = '0'also test the same thing.There is no real difference between the four.