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.
Since you said you need
insert into select
give this a try then, and add conditions as your desire..To give a better answer, you may need to at least show your current query and what mechanism makes the increment, table schema... I could even assume you are already at this step anyway...
I think following workaround will help you.
Hope this helps
If your source and destination columns are in the sames order then just do: