Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SET vs SELECT
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Titre:
Versions des environnements
SQL Server:
SQL Server 2014
Application:
Web
Divers
Thread ID:
01611728
Message ID:
01611736
Vues:
43
>>Another newbie question.
>>
>>I can set a value to a variable in a stored procedure using SET or SELECT. E.g.
>>
>>set @MyVar = 0
>>select @MyVar = 0
>>
>>
>>Which approach is a better practice and why?
>>
>>TIA
>
>For a single variable assignment it doesn't really matter. With SELECT you can set multiple variables at once so if you need to set values for several variables, I prefer SELECT statement.
>
>Also, if you use
>
>select @myVar = someColumn where ConditionEvaluatesToFalse
>
>then the initial value of the @myVar (NULL) will not change. Just be aware of that fact.

Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform