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:
01077697
Vues:
22
This message has been marked as a message which has helped to the initial question of the thread.
>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,
>Einar

Einar,
It works for me.
I have a table with field Test binary(1024)
The test field is updated that way:
UPDATE Town SET Test = (0x45+Kod)
Kod is other field from that table that has values from 1 to 176

In SQL MStudio I do:
DECLARE @data binary(1024)
SET @data = (SELECT Test FROM Town WHERE Kod = 1)
print @data -- 0x(1022 zeroes here)46 what is the result I expected.
UPDATE: If you want the result with less zeroes change the type to be varbinary(), but because I nevber used that type of field till now I can't tell you if this is a new in SQL Server 2005 or not :o(. I must check tomorow.
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform