• Not sure exactly what you are looking for here.   Your words didn't explain in much detail what you are looking for, so I made a guess based on what I did see.   I suspect you may be looking to flatten out your results, but again, it's just a guess.   A simple PIVOT might do the trick, but there's no avoiding mentioning all the possible values, and doing so twice.
    Take a look at this and see if it's what you're looking for:

    CREATE TABLE #temptable (
        sessionid INT,
        Question VARCHAR(50),
        Response VARCHAR(50)
    );
    --=======================================================
    -- INSERT CODE TO POPULATE #temptable here
    --=======================================================
    CREATE TABLE #QUESTION_CODES (
        Question varchar(10) NOT NULL PRIMARY KEY CLUSTERED,
        QuestionType varchar(50)
    );
    INSERT INTO #QUESTION_CODES (Question, QuestionType)
    SELECT Question, QuestionType
    FROM (
        VALUES    ('2825', 'Invoice number'),
                ('2826', 'Invoice date'),
                ('2827', 'Vessel'),
                ('2828', 'Counterparty'),
                ('2829', 'Product'),
                ('2830', 'QuantityMT'),
                ('2831', 'Price USD'),
                ('2832', 'Invoice amount USD'),
                ('2834', 'Supporting documentation ( contract, etc.)'),
                ('2868', 'Supporting documentation reference number'),
                ('2869', 'Supporting documentation date'),
                ('2870', 'Terms of sale'),
                ('2872', 'Shipping document'),
                ('2873', 'Shipping document date'),
                ('2875', 'Supporting documentation'),
                ('2876', 'Reference start period'),
                ('2878', 'Notes'),
                ('2879', 'Please upload sales invoice'),
                ('2880', 'Please upload contract'),
                ('2881', 'Please upload shipping document'),
                ('2882', 'Please upload statement'),
                ('2883', 'Reference end period'),
                ('3154', 'Remarks')
            ) AS X (Question, QuestionType);

    WITH ALL_DATA AS (

        SELECT T.*, Q.QuestionType
        FROM #temptable AS T
            INNER JOIN #QUESTION_CODES AS Q
            ON T.Question = Q.Question
    )
    SELECT sessionid, [Invoice Number], [Invoice Date], [Vessel], [Counterparty], [Product], [QuantityMT],
        [Price USD], [Invoice amount USD], [Supporting documentation ( contract, etc.)],
        [Supporting documentation reference number], [Supporting documentation date],
        [Terms of sale], [Shipping document], [Shipping document date], [Supporting documentation],
        [Reference start period], [Notes], [Please upload sales invoice], [Please upload contract],
        [Please upload shipping document], [Please upload statement], [Reference end period], [Remarks]
    FROM ALL_DATA
        PIVOT (MAX(Response) FOR QuestionType IN (
            [Invoice Number], [Invoice Date], [Vessel], [Counterparty], [Product], [QuantityMT],
            [Price USD], [Invoice amount USD], [Supporting documentation ( contract, etc.)],
            [Supporting documentation reference number], [Supporting documentation date],
            [Terms of sale], [Shipping document], [Shipping document date], [Supporting documentation],
            [Reference start period], [Notes], [Please upload sales invoice], [Please upload contract],
            [Please upload shipping document], [Please upload statement], [Reference end period], [Remarks])) AS PVT
    ORDER BY sessionid;

    DROP TABLE #QUESTION_CODES;
    DROP TABLE #temptable;

    I had to assume what the meaning of the values you listed in the query were, and that meaning (QuestionType) may be entirely wrong.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)