May 27, 2009 at 6:59 am
I have a query where I want to use a DECLARE statement, but the variable I am declaring can be one of about 5 options. Is it possible to use DECLARE in this way?
ex.
DECLARE@symbol varchar (5)
SET@symbol IN ('ABK','UYG','AIG','SKF')
May 27, 2009 at 7:13 am
I am not sure what you tried to do here but technically you cannot declare and set variable values in that fashion. Otherwise, you can use table variables to store array values into rows.
--Ramesh
May 27, 2009 at 7:16 am
DECLARE @symbol table (id int, alpha varchar(5))
INSERT INTO @symbol
SELECT 1,'ABK' UNION
SELECT 2,'UYG'UNION
SELECT 3,'AIG' UNION
SELECT 4,'SKF'
select * from @symbol;
U do have to use table variables, and then retrieve the variable u need from the select query
May 27, 2009 at 7:42 am
You could set it this way, not that I'd want to:
DECLARE @myval varchar(max)
SET @myval = '(''5'',''4'',''3'',''2'')'
The two single quotes will turn into one inside the variable.
But, the real question is, what are you trying to do?
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
May 27, 2009 at 7:45 am
Mayank Khatri (5/27/2009)
DECLARE @symbol table (id int, alpha varchar(5))
INSERT INTO @symbol
SELECT 1,'ABK' UNION
SELECT 2,'UYG'UNION
SELECT 3,'AIG' UNION
SELECT 4,'SKF'
select * from @symbol;
U do have to use table variables, and then retrieve the variable u need from the select query
This appears to suit my purposes. THANKS!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply