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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:31:08+00:00 2026-05-15T17:31:08+00:00

I know this question could have passed a few times here but I haven’t

  • 0

I know this question could have passed a few times here but I haven’t really found a workaround whatsoever. Also could my question be a little different.

Situation is: I have a table with 130 columns (+100.000 rows), and the number of columns will even increase in the future. For this reason I would like to define the selection of the columns as [select all but one]

AS I want to duplicate a row with [select all] I get an error on the primary key -> the nc_ID because -of course- it tries to duplicated this value also instead of increasing it by one.

It is obvious that the column that I want to excluded from the selection is the first one, the nc_ID. I read and heard that this kind of [select all but one] solutions can only be accomplished with dynamic sql. If so could someone explain me via a piece if sql code?


INSERT into TableName (all columns except the first *nc_ID*)
Select * From TableName Where nc_ID=12345;

Thanks in advance!

  • 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-15T17:31:09+00:00Added an answer on May 15, 2026 at 5:31 pm

    Were you asking how to do this in dynamic SQL? – Something like the following should work.

    (Obligatory link to The Curse and Blessings of Dynamic SQL)

    DECLARE @TableName varchar(500)
    DECLARE @nc_ID INT
    SET @nc_ID = 12345
    SET @TableName = '[dbo].[TableName]'
    
    DECLARE @Dynsql nvarchar(max)
    
    SELECT @Dynsql = ISNULL(@Dynsql + ',','') + QUOTENAME(name) FROM sys.columns
    WHERE object_id = object_id(@TableName) and is_identity = 0 and is_computed = 0
    ORDER BY column_id
    
    IF @@ROWCOUNT=0
    RAISERROR('%s not found in sys.columns',16,1, @TableName)
    
    SET @Dynsql = 'INSERT INTO  ' + @TableName + '
               ('+ @Dynsql +')
    SELECT '+ @Dynsql +'
      FROM ' + @TableName + '
    WHERE  nc_ID = @nc_ID'
    
    EXEC sp_executesql @Dynsql, N'@nc_ID int',@nc_ID=@nc_ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question was asked here many times before but I am still
I know this question might sound quite silly, but I somehow found myself stuck
I know this question as been asked countless times, but believe me I've searched
Introduction: Now I know this question could be very broad and it would be
I know this is not the only question out there, but I still couldn't
I know this question has been asked a couple of times before. I m
I know this question has been asked before however the answers I found where
I know this question is typique and it was asked many times in the
I know this question might be little silly but I can't seem to find
I know this question was asked for many times, and it may look like

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.