This is my statement
IF (@UserName IS NULL AND @EditorKey IS NULL) OR (@UserName IS NOT NULL AND @EditorKey IS NOT NULL) BEGIN
RAISERROR ('One of @UserName, @EditorKey must be non-null.', 15, 0)
RETURN
END
What I want is to be able to do something like this:
IF (@UserName IS NOT NULL) XOR (@EditorKey IS NOT NULL) BEGIN
RAISERROR ('One of @UserName, @EditorKey must be non-null.', 15, 0)
RETURN
END
For two parameters it isn’t that big of a deal, but some procs have three or four where in only one may be passed and the rest should be null.
Not very succinct, but you could expand out the logic like this:
Or use the bitwise XOR operator (^):
You can use a similar approach where there are three or four parameters, and exactly one must have a value: