Let's say I have a table with 3 columns; people's salaries, how much they spend in a year, and their credit score.
Next, let's say I want to flag people with low salaries, who spend most of what they earn, and who also have bad credit scores. When doing some analytics on it, I may have to say something like
when(
salary < 40000
and
spent > 0.75*salary
and
credit_score < 500
) then do_something
It's possible that I may have to reference those three conditions multiple times throughout a query. Can I just create a boolean that'll encompass all three of those?
For example
Declare @flag boolean
@flag = case
when(
salary < 40000
and
spent > 0.75*salary
and
credit_score < 500
) then true
else false
/* Then later on in the program */
when(
@flag
) then do_something
So the aim of the boolean is to shorten that three-condition statement into one variable and then the variable is referenced instead of the three statements. And every time it checks a row of data, it computes @flag and acts upon the result.