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 6563617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:52:18+00:00 2026-05-25T13:52:18+00:00

I am making a query to create a table which has twice elements in

  • 0

I am making a query to create a table which has twice elements in SQL

SELECT [att1]
      ,[att2]
      ,[att3]
      ,[att4]
      ,[att5]
      ,[att6]
      ,[att7]
      ,[att8]
      ,[att9]
      ,[att10]
      ,att11 = att1,
       att12 = att2,
       att13 = att3,
       att14 = att4,
       att15 = att5,
       att16 = att6,
       att17 = att7,
       att18 = att8,
       att19 = att9,
       att20 = att10
INTO Table_20
FROM Table_10;

What would be the best way to make this dynamic and if I have a table with 30 atts, make a table with 30 * 2 atts (double the size)?

  • 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-25T13:52:19+00:00Added an answer on May 25, 2026 at 1:52 pm
    DECLARE 
        @table NVARCHAR(512) = N'dbo.Table_10';
        @sql   NVARCHAR(MAX) = N'',
        @c     INT;
    
    SELECT @sql += N',' + name 
        FROM sys.columns 
        WHERE [object_id] = OBJECT_ID(@table) 
        AND name LIKE 'att%';
    
    SELECT @c = @@ROWCOUNT;
    
    SELECT @sql += N',att' + CONVERT(VARCHAR(12), 
          @c + CONVERT(INT, REPLACE(name, 'att', '')))
          + ' = ' + name 
        FROM sys.columns  
        WHERE [object_id] = OBJECT_ID(@table) 
        AND name LIKE 'att%';
    
    SELECT @sql = N'SELECT ' + STUFF(@sql, 1, 1, '') 
        + ' INTO dbo.Table_20 FROM ' + @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'm still a learning user of SQL-SERVER2005. Here is my table structure CREATE TABLE
I need to create native SQL query with couple of unions and subqueries. It'll
setup: mysql> create table product_stock( product_id integer, qty integer, branch_id integer); Query OK, 0
My context model has a couple of related tables: CREATE TABLE CarSystem.Reads ( ReadId
My table has a timestamp column named RowVer which LINQ maps to type System.Data.Linq.Binary.
I have a large query (not written by me, but I'm making some modifications).
Making an adobe flex ui in which data that is calculated must use proprietary
I am making a PHP web Application in which i am using MySQL as
I need to create a view or a table valued function that returns one
Suppose we have 2 tables, a and b: CREATE TABLE a (id_a INT NOT

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.