DataAnalyst011 (12/12/2012)
Thanks for your reply also.I didn't do a very good job setting this up. I just tried to create a quick example to ask about a concept - Is it possible to loop through multiple variables in a single statement. In my production project, the values don't exist and I use the variables to print them into a row for a business process need.
A table called x has these values in a Prog column: 1, 2, 3, 4
What I want to do is pass each of those variables in the below statement:
insert into q (resultcolumn)
select @prog
from a
and the results in resultcolumn is:
1
2
3
4
This would keep me from declaring and setting the value for @prog 4 times (one for each of the numbers). Does that make sense?
If the maximum number of different possible values isn't large, maybe a PIVOT would work:
CREATE TABLE #X (
Prog INT
)
INSERT INTO #X VALUES (1), (2), (3), (4)
SELECT [1] AS N1, [2] AS N2, [3] AS N3, [4] AS N4
FROM #X
PIVOT (MAX(Prog) FOR Prog IN ([1], [2], [3], [4])) AS PVT
DROP TABLE #X
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)