Link to home
Start Free TrialLog in
Avatar of barnesco
barnesco

asked on

Returning parameter from a select statement

How do I return the below to a parameter:

DECLARE @ReturnCOID int

SELECT COID FROM Order
ASKER CERTIFIED SOLUTION
Avatar of D B
D B
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

it should like

select @ReturnCOID=COID  FROM Order .
Important in dbbisshop's comment
"Note that this must return only one row"

If that is possible causing problems there are ways around that , but see they still give a correct value in all cases for what you intend to do.
Some examples
Select @ReturnCOID = max(COID) from Order

Open in new window

or
Select @ReturnCOID = top 1 COID from Order order by orderdate desc

Open in new window