Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

t-sql get variable value from string with variable name

Tags:

tsql

Is there a way to convert @my_variable string into a value of @my_variable?

I have a table which stores names of variables. I need to get the value of this variable. Something like this:

DECLARE @second_variable AS NVARCHAR(20);
DECLARE @first_variable AS NVARCHAR(20);
SET @first_variable = '20';
SET @second_variable = SELECT '@first_variable'; --here I want that @second variable be assigned a value of "20".
like image 703
Markus Avatar asked Nov 06 '22 15:11

Markus


1 Answers

The most likely solution to your problem is to address/change/fix the design that requires why you would have a table that stores the names of variables.

like image 81
KM. Avatar answered Nov 18 '22 22:11

KM.