How to display column descriptions as the column headers.

Joel Dittoe 0 Reputation points
2023-02-28T16:31:01.1433333+00:00

So I have one table with the table fieldID and Descriptions. But I have another table with the field Ids as the column names. I need the descriptions to replace the column names to give an accurate representation of what is being displayed. I would appreciate any help!

SQL Server Other
{count} votes

3 answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2023-02-28T16:45:03.2866667+00:00

    just use column name alias:

    select col1 as "this is a description", ....

    as your requirement is to dynamically build the select statement what language will you be using? also do you know the column names (fieldids) in advance, or do you query for them?


  2. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2023-02-28T22:53:08.38+00:00

    To do this in SQL Server, you would be in for an advanced exercise in dynamic SQL.

    But I assume that you have a UI where you display this information. You should probably return column names and descriptions from the database in normal format, and the get the descriptions in place in the UI.

    0 comments No comments

  3. LiHongMSFT-4306 31,566 Reputation points
    2023-03-01T02:47:23.34+00:00

    Hi @Joel Dittoe

    Please check this sample: code.txt

    Cannot post code here due to unknown reason, please see the attached .txt file above.

    Best regards,

    Cosmog Hong


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.