jeudi 8 janvier 2015

tSQL: Resolving a local variable to be the value of the referenced local variable


Vote count:

0




I have a local variable that is the name of another local variable. I want to change the value of the first local variable to the value of the another local variable. Without hard coding, what is the best way to do this. In addition, I only have read access to the database. (Preferably I don't want to have write anything into the database)


example:



DECLARE @x1 VARCHAR(10), @x2 VARCHAR(10), @x3 VARCHAR(10), @x4 VARCHAR(10)
DECLARE @y VARCHAR(10)

SET @var1 = 'abc'
SET @var2 = 'def'
SET @var3 = 'ghi'
SET @var4 = 'jkl'


I want to change the value of @y to 'abc' if @y is initially equals to @var1, 'def' if initial value is @var2 and so on


Does anyone know how to do this without hard coding in the value since i can potentially have many more local variables?



asked 30 secs ago







tSQL: Resolving a local variable to be the value of the referenced local variable

Aucun commentaire:

Enregistrer un commentaire