I'd like to display the results of a query, and I'd like to capture a column's value at the same time. The FROM
and WHERE
are the same in both queries. Can I do both in one query, or is it easier/better to just do the query twice, like this?
DECLARE @fooId INT
SET @fooId = (SELECT FooId FROM Bar WHERE SnuhId = 5)
SELECT * FROM Bar WHERE SnuhId = 5
Unfortunately it has to be done in two operations.
Test:
DECLARE @VAR DATETIME
SELECT @VAR=GETDATE(), GETDATE()
Yields error message 141.
Here's another SO post on this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With