select column from table in MS SQL based on value of an identifier column
Posted on 2014-12-05
This may sound a little convoluted, but I need to know if this is possible. This is a basic example of the data I have now (in a single table) and what I'm trying to select from it:
column1, column2, column3, column4, column5
DATA IN THOSE COLUMNS:
column2, a, b, c, d
column3, e, f, g, h
column4, i, j, k, l
column5, m, n, o, p
I want to select the value of the column identified in column1. So a "select ___ from table" would yield this:
In other words, whatever is in column1, that determines what column I want the data from. In the first row, column1 is "column2", so return "a".
I need the query to put the result in a specific column name, such as "select ___ as columname from table".
If this is possible, I need to figure out the syntax.