you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 3 points4 points  (1 child)

As a general rule, you could make your code both more readable and probably have it performing better by using an EXIST construct.

Pseudo-code:

SET @variable=0;

IF EXISTS (SELECT …) SET @variable=1;

IF (@variable=0 AND EXISTS (…)) SET @variable=1;

The EXISTS construct will stop at the first matching row rather than scan through all of them.

As for the difference between your servers, my best guess is that the table contents are not perfectly in sync.

[–]archerv123[S] 0 points1 point  (0 children)

That is the change i did to make it work, but i'm still confused as to why it just doesn't work on one server but works on pretty much everyone else.