Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Assign value to @local_variable
Message
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01077688
Message ID:
01077692
Views:
36
This message has been marked as a message which has helped to the initial question of the thread.
Einar,

The best way to do things in SQL Server is using set oriented approch. Something like
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,
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform