Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Declared variable in SELECT statement

Status
Not open for further replies.

ikim2000

MIS
May 23, 2002
22
CA
What does the select statement do below and what does the declared variable do in that statement? I seen it being used with "WHERE" as well. Thx, Ik.
========================================================
declare @vID int
select @vID = CustomerID from tblCustomer
 
Hi,
This is straight out of SQL BOL:

SELECT @local_variable
Specifies that the given local variable (created using DECLARE @local_variable) should be set to the specified expression.

SELECT @local_variable is usually used to return a single value into the variable. It can return multiple values if, for example, expression is the name of a column. If the SELECT statement returns more than one value, the variable is assigned the last value returned.

If the SELECT statement returns no rows, the variable retains its present value. If expression is a scalar subquery that returns no value, the variable is set to NULL.

Hope that answers your question.
~Deeba~
 
The select statement assigns the value of CustomerID from the tblCustomer table to the variable vID.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top