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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:51:15+00:00 2026-06-17T18:51:15+00:00

I use MS SQL in combination with SSIS where I need to copy and

  • 0

I use MS SQL in combination with SSIS where I need to copy and paste rows of a table (same table for source and destination) for a given DocumentID while also incrementing the “subversion” column.

Example:

DocumentID=123 | Location=a | Version=2 |Subversion=4
DocumentID=123 | Location=b | Version=2 |Subversion=4
DocumentID=123 | Location=c | Version=2 |Subversion=4

after copy:

DocumentID=123 | Location=a | Version=2 |Subversion=5
DocumentID=123 | Location=b | Version=2 |Subversion=5
DocumentID=123 | Location=c | Version=2 |Subversion=5

Within SSIS I already increment the max(Subversion) (from 4 to 5 in the example).
What I need is a select/insert statement to copy the data.

Since this table has around 150 columns I was hoping for a way without listing all columns but I couldn’t find any information if that is even possible.

I’ve tried Insert into in combination with Select but it always ended in errors (aggregate issues).

  Insert Into MyTable (AllMyColumns)
  select (AllmyColumns)
  from MyTable
  where DocumentID =123 AND ...

How do I need to build this statement?

thanks for your help.

  • 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-06-17T18:51:16+00:00Added an answer on June 17, 2026 at 6:51 pm

    I think following workaround will help you.

    --Move incremental rows to the #temp table
    Select * into #temp from MyTable where DocumentID=123 and ......
    
    Declare @version varchar(20)
    
    Select @version = Max(SubVersion) from #temp
    
    --To increment the value
    set @version='Subversion='+Cast(Substring(@version,charindex('=',@version)+1,len(@version)) as int)+1
    
    --To update the value into temp
    update #temp set SubVersion=@version
    
    --Now insert into your table
    insert into MyTable
    Select * from #temp
    
    --drop the temp table
    drop table #temp
    

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use SQL Server 2008 R2 and have a table that I want no
I use SQL Server 2005. I have a simple logging table that my web
I use SQL Server 2008 and have a table with 5 char typed columns.
I have a table that I need to normalize with many fields In SQL-Server
i'm planning to use a combination of entity framework + plain sql access for
I need help with SQL Server Table Column. I´m trying to rename Column Name,
How use sql like in PyMongo? >>> db.houses.find().count() 11616 >>> db.houses.find({hid:u16999}).count() 1 >>> db.houses.find({hid:u/9/}).count()
I use SQL at work to gather info, but nothing too advanced (yet). I
I want to use sql JOIN with COUNT in a way that using the
I'm trying to use SQL Server Management Studio to edit database tables. But I

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.