I'm trying to pass column names using a string split because I need the values from that table to join with another table.
I've already achieved this in Postgresql where I get the values from these columns:
SELECT unnest(array["column_name1","column_name2","column_name3" AS "amount" FROM table1
The unnest in combination with the quotes around the column names returns an array to a set of row for every value.
Amount 307579.00 25579.00 212871.00
Now I want to do the same in MS Server:
DECLARE @amount NVARCHAR(50) = 'column_name1/column_name2/column_name3' SELECT "value" from string_split(@amount,'/')
But this only gives me the literal string:
Amount column_name1 column_name2 column_name3
I've been trying and searching how to pass an elemant that will read as a column name and shows the values in one column like the first example, maybe I shouldn't use the string splitter etc. Kinda stuck on this..