Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Assign value to @local_variable
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01077688
Message ID:
01077701
Vues:
39
Sergey,
I am not sure I understand 100% (I am getting tierd and hungry and I am out of coffee).
Are you saying that:
DECLARE @Data binary(1024)
SELECT @Data = Data FROM myTable WHERE Id=2
is prefered over
DECLARE @Data binary(1024)
SET @Data = (SELECT Data FROM myTable WHERE Id=2)
<pre>
?

After using an Id that exists I get the desired result using both approaches. :)

Now to the part I don't understand. The SELECT statement with UNION ALL was that related to this post?

Einar



>Einar,
>
>The best way to do things in SQL Server is using set oriented approch. Something like <pre>
>SELECT ID, Data FROM mytable WHERE id=2
>UNION ALL
>...
>
To answer your question, try
> SELECT @Data = Data FROM myTable WHERE Id = 2
>
>
>
>>How can I assign a value to a @local_variable, when the value is a field value from a SELECT statement?
>>I am not sure if my question makes sense (even to me<s>), so I will try to explain it further.
>>
>>Considder the following:
>>
>>DECLARE @rows int
>>SET @rows = (SELECT COUNT(*) FROM Customers)
>>
>>@rows will now equal the number of records in the Customers table. That was easy, but that is not what I need.
>>
>>Assume I have the following table called myTable:
>>
>>Id   Data
>>---  -----
>>1    <binary>
>>2    <binary>
>>3    <binary>
>>
>>
>>I want to store the binary data that is stored in the data column in row where Id = 2. What would the code look like?
>>
>>
>>DECLARE @Data binary(1024)
>>SET @Data = (SELECT Data FROM myTable WHERE Id = 2)
>>
>>
>>But the code above does not work the way I expect it to.
>>I hope I have explained my problem well enough. Please let me know if it is still unclear.
>>
>>Thanks,
>>
Semper ubi sub ubi.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform