How to execute a select within an IF/CASE condition?

Asked

Viewed 96 times

1

would like to know how I can use a select as a true or false condition within a case or IF:

The query to return true or false is this:

SELECT * FROM Funcionario f WHERE (f.Email IS NULL OR RTRIM(f.Email)='') AND f.FuncionarioID=@funcionarioID

The condition is, if this select returns a True If False line.

Something like this:

IF (SELECT * FROM Funcionario f WHERE (f.Email IS NULL OR RTRIM(f.Email)='') AND f.FuncionarioID=1) THEN END

1 answer

1

You have to select the boolean expression you need. The * is to pick up all columns. The SELECT ***select* the information you need, if it’s a condition, use it there.

IF (SELECT (f.Email IS NULL OR RTRIM(f.Email) = '') FROM Funcionario f WHERE f.FuncionarioID = 1) THEN END

I put in the Github for future reference.

  • I need to get the return lines of this select know, I saw that in sql @@ROWCOUNT does this.

  • @@ROWCOUNT It’s none of your business, at least not what’s in the question. I answered what was asked, if your problem is another, need to create a new question.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.