I need assign the following SQL Server's query result value to the variable called @value1
SELECT *
FROM customer
WHERE apo_id = '2589';
How can I do this in SQL Server?
1 - First declare your variable of type table.
declare @value1 table(
--YOUR TABLE DEFINITION ex: ValueId int,
)
2 - Insert into your variable
insert into @value1 select * from customer WHERE apo_id = '2589';
Hope that helps, thanks.
$value1a variable in your client programming language?@, not a$. If you're trying to put the results set into a variable in your application code the things you should be tagging are the application code language, and included your existing application code.DECLARE @Var Datatype; SELECT @Var = Column FROM customer WHERE apo_id = '2589';Note this won't work as expected if you have more than 1 row with the conditionapo_id = '2589'*, @Sami , I suspect they want to store all the columns (and rows?) into a single variable. Difficult to really know what they are after at the moment though.