Hi @Anonymous ,
Welcome to microsoft TSQL forum!
As ErlandSommarskog said, when you post a question, please post the relevant details.
Here are some tests based on my understanding, please refer to:
CREATE TABLE #DataTable(ID INT,A INT)
INSERT INTO #DataTable VALUES(100,1),(101,2),(102,3)
CREATE TABLE #RefTable([QuestionID Discription] INT,[How you feeling?] CHAR(15))
INSERT INTO #RefTable VALUES(1,'Awesome'),(2,'Good'),(3,'Bad')
SELECT * FROM #DataTable
SELECT * FROM #RefTable
SELECT d.ID,r.[How you feeling?] FROM #DataTable d
INNER JOIN #RefTable r
ON d.A=r.[QuestionID Discription]
Output:
Or:
CREATE TABLE #DataTable2(ID INT,A INT)
INSERT INTO #DataTable2 VALUES(100,1),(101,2),(102,3)
CREATE TABLE #RefTable2(QuestionID CHAR(25),Discription CHAR(25),[1] CHAR(25),[2] CHAR(25),[3] CHAR(25))
INSERT INTO #RefTable2 VALUES('A','How you feeling?','Awesome','Good','Bad')
SELECT * FROM #DataTable2
SELECT * FROM #RefTable2
;WITH cte
as(SELECT * FROM #RefTable2
UNPIVOT (val for num in ([1],[2],[3])) as t)
SELECT ID,val AS [How you feeling?] FROM #DataTable2 d
INNER JOIN cte c ON d.A=c.num
Output:
If you have any question, please feel free to let me know.
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.