Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Update from Select
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
01673282
Message ID:
01673314
Vues:
47
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform