To be honest, I’ve used this very little. For my querying and manipulating needs, things like Case statements have usually been sufficient.

But I appreciate it covers an important concept of logic. So here are some good examples.

In its simplest form, it is like this:

If

1 = 1 Print ‘This is True!’

Else Print ‘This is not True!’

— Use Adventureworks

Select * From Production.Product Where Name Like ‘%Ball%’

— 3 rows

If

(Select Count(*) From Production.Product Where Name Like ‘%Ball%’) >= 3

Print ‘3 balls or more’

Else Print ‘Less than 3 balls’

— Result:

— 3 balls or more