kcmoore
asked on
Parameter in Select statement as column name
I'm trying to select a specific column name from a table based on a string from a parameter.
How can I do this?
Code below...what I am trying to return is basically,
Select QA1 from @TEMP
if @QA = QA1.
How can I do this?
Code below...what I am trying to return is basically,
Select QA1 from @TEMP
if @QA = QA1.
DECLARE @VAL INT
SET @VAL = 2
DECLARE @QA VARCHAR(5)
SET @QA = 'QA'+CAST(@VAL AS VARCHAR(1))
DECLARE @TEMP TABLE
( PK INT, QA1 VARCHAR(4), QA2 VARCHAR(4) )
INSERT INTO @TEMP
SELECT 1,'ASDF','JHFJ'
select * from @temp
SELECT @QA
FROM @TEMP
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.