Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Update from Select
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
01673282
Message ID:
01673314
Views:
46
I think there is no guarantee and I personally don't use the mixture of variables and columns in one statement, I'd rather just update the columns and use OUTPUT clause to get my variables.

>Sorry for another question.
>
>In the UPDATE command, the order of evaluation is always as it is in the statement, left to right?
>Let me show you and example:
>
>update t1 set @Qty2Use = case when t1.qty_left >= @QtyUseRemain then @QtyUseRemain else t1.qty_left end,  
>t1.qty_left = t1.qty_left - @Qty2Use, 
>@QtyUseRemain = @QtyUseRemain - @Qty2Use,
>t1.rec_id = case when t1.qty_left > 0 then '1' else '2' end,
>@QtyLeft = t1.qty_left, 
>....
>
>
>In my case, after the first iteration the value of the variable @QtyLeft remains greater than 0 even though the quantity should be reduced.
>So, my question is, is the line
>
>t1.qty_left = t1.qty_left - @Qty2Use, 
>
>always executed before the line:
>
>@QtyLeft = t1.qty_left, 
>
>
>Or it is random?
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform