Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Set selected value to a variable
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01544218
Message ID:
01544220
Vues:
29
>Hi,
>
>The only way I found that I can assign a value selected in SQL Select to a variable as following:
>
>
>select @MyVar = (select MyColumn1 from MyTable where MyColumn2 = 'SomeValue')
>
>
>Is the above the only way to do it? Or there is a better approach? TIA.

Another way is
select @MyVar = MyColumn1 from myTable
The difference between these two methods is that the first will always change the @MyVar variable. In the second case, if the select statement does not produce rows, the original value of @MyVar will not change.
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