Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7535873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:25:07+00:00 2026-05-30T06:25:07+00:00

I have a table with over 400 columns, and these are named with our

  • 0

I have a table with over 400 columns, and these are named with our vendor’s archaic naming system. I need to move this data into a new table which uses our company’s naming conventions, so I have to change the names of these 400 columns.

Fortunately, I also have a table that cross-references the current column names with what they should become, like so:

Acronym  | Name
----------------
A        | ColumnNameA
B        | ColumnNameB
C        | ColumnNameC

etc…

So my question is this:
If it were only a few rows, I could easily do

SELECT 
   A AS ColumnNameA, 
   B AS ColumnNameB 
FROM 
   Table

But there are just too many columns to do this by hand. What’s the best way to dynamically change column names in a SELECT statement based off of a cross-ref table?

My effort so far:

I was thinking something along the lines of

SET @sqlCommand = 'SELECT ' + @columns + ' FROM Table'
EXEC (@sqlCommand)

but I have no idea how to set @columns to be a dynamically generated list of all the acronyms as the final column names. Is this even a viable approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T06:25:08+00:00Added an answer on May 30, 2026 at 6:25 am
    DECLARE @sql NVARCHAR(MAX) = N'';
    
    SELECT @sql += ',' + QUOTENAME(Acronym) + ' AS ' + QUOTENAME(Name)
    FROM dbo.AcronymTable;
    
    SET @sql = 'SELECT ' + STUFF(@sql, 1, 1, N'') + ' FROM dbo.Table;';
    
    PRINT @sql;
    --EXEC sp_executesql @sql;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have no control over how the data is saved in this table. However,
I have a table with over million rows. I need to reset sequence and
I have a mysql table with over 30 million records that was originally being
I have table with a unique auto-incremental primary key. Over time, entries may be
I have table with few rows, after use hover mouse over row I want
I have a table where i want to change cell background on mouse over
I have a table like Table1: col1 col2 col3 and have an index over
I have a table with below structure. I am not having control over changing
Say if I have a large dataset, the table has well over a million
I have no control over database schema and have the following (simplified) table structure:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.