Similarly, the order of evaluation can affect the outcome when passing variables and parameters as arguments.
Consider the following statements:
declare @A Address declare @Order varchar(20)
select @A = new Address('95444', '123 Port Avenue')
select case when Utility.F(@A)>Utility.G(@A) then ‘Left’ else ‘Right’ end
select @Order = case when utility.F(@A) > utility.G(@A) then 'Left' else 'Right' end
The new Address has a five-character zip code field. When the case expression is evaluated, depending on whether the left or right operand of the comparison is evaluated first, the comparison is either 1>0 or 0>1, and the @Order variable is set to ‘Left’ or ‘Right’ accordingly.
As for column arguments, the expression value depends on the evaluation order. Depending on whether the left or right operand of the comparison is evaluated first, the resulting value of the zip field of the Address instance referenced by @A is either “95444-4321” or “95444-1234.”