1

I have a query in SQL Server stored procedure like this:

IF (@EDITED = 1) AND (EXISTS (SELECT 1 FROM InventarizacijaZurnals WHERE RECORD_UNIQUE_ID=@RECORD_UNIQUE_ID)) ....

My question is - will query part after AND always be executed even if first statement is True? I know some languages do it and some doesn't. How does it work in SQL Server? Can't seem to find a clear answer online.

Janeks Bergs
  • 224
  • 3
  • 13
  • _"I know some languages do it"_ Uh, no, not what you said. Short-circuiting can occur for `true` in an `or` clause, vs `false` in an `and` clause. Not `true`/`and`. – underscore_d Dec 08 '17 at 11:45
  • 1
    duplicate of [Is MS-SQL AND/OR conditional (perform short-circuit evaluation)?](https://stackoverflow.com/questions/46134872/is-ms-sql-and-or-conditional-perform-short-circuit-evaluation) and, more generally, [Is the SQL WHERE clause short-circuit evaluated?](https://stackoverflow.com/questions/789231/is-the-sql-where-clause-short-circuit-evaluated) – underscore_d Dec 08 '17 at 11:46
  • I should clarify that what I said above was about short-circuiting generally. It seems implementation-defined whether SQL implementations can do that. Also, I'm not sure how `NULL`s affect the feasibility. – underscore_d Dec 08 '17 at 12:09

1 Answers1

0

always be executed even if first statement is True

Do you mean first statement is False, not True? When first statement is True we have still possibility that second will be false and then "True and False" is just False. So in that case second query part will be executed.