I have n number of @BLOCn variables.
Is it possible to concatenate a variable name so that one can use the loop counter as part of it? For example:
DECLARE @BLOC1 int, @i int, @MAX int, @QTY int;
SET @i = 1;
SET @MAX = 1;
SET @BLOC1 = 12;
WHILE @i <= @MAX
BEGIN
SET @QTY = FLOOR('BLOC'+@i)
...
END
SELECT @QTY
So far, I'm getting this error:
Conversion failed when converting the varchar value 'BLOC' to data type int.
I'm basically looking for the SQL equivalent of Javascript's:
var foo = 'var';
var bar = 'Name';
window[foo + bar] = 'hello';
alert(varName);
nvariables have a table variable withnrows. What are you actually trying to do? The code you have shown repeatedly assigning to@QTYand never using the assignment doesn't make much sense.