How do I create/declare variables with a counter in the name on a MS SQL Server?
I have a “for-like” loop with CURSOR and
WHILE @@FETCH_STATUS = 0
BUT: the number of those values is changing continuously. So i want to write every value in an own variable. My goal is to get var-names like : @var1, next loop @var2, next @var3 etc.
Well
SET @counter = (@counter + 1)
is not THAT difficult, but how do I add the value(!) of @counter to the name(!) of @var?
THX a LOT!
I think you should create a temp table to store these variables. For example:
Now insert a new value:
To get this value
[i]use simple select: