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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

put select value into a variable

Status
Not open for further replies.

fgeorge

Programmer
Jun 28, 2002
76
NG
i have created a select statement..
select a,b,c from xyz

what i do next will depend on what is in the a field..

how do i get this value into a variable as i want to use it in a CASE Statement?
 
Is the CASE statement going to be contained in "select a,b,c from xyz", or is the select statement supposed to be in the CASE statement?



Dan.
 
If you want to get values to variables use:

DECLARE @vat_a some_type,
@vat_b some_type,
@vat_c some_type

SELECT @var_a = a, @var_b = b, @var_c = c FROM xyz


or based on what you want to do , you can use CASE statemt in select:

SELECT CASE WHEN a = some_value1 THEN something1
WHEN a = some_value2 THEN something2
ELSE something3 AS column_name,
b,c

Zhavic

---------------------------------------------------------------
In the 1960s you needed the power of two Comodore64s to get a rocket to the moon. Now you need a machine which is a vast number of times more powerful just to run the most popular GUI.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top