Copy data from one table to another table with change in identity column values

HI,
I have a table
Create table test(a int identity(1,1), b int)
insert into test(b) values(12)
insert into test(b) values(30)
insert into test(b) values(65)
insert into test(b) values(78)
insert into test(b) values(36)

o/p
a b
1 12
2 30
3 65
4 78
5 36

i need to copy the table into another table with creating the new
table
we had a option
select * into newtable from oldtable
here the data in the oldtable will e copied to new table without
creating new table
but i need to copy the data as shown below with out creating new
table
o/p
a b
11 12
12 30
13 65
14 78
15 36

Thanks,
Satish
Satish [ Mo, 20 August 2007 11:21 ] [ ID #1799805 ]

Re: Copy data from one table to another table with change in identity column values

If I understand your question, you want to insert the data from table
test into an already existing table.

INSERT existingtable
SELECT a, b
FROM test

Roy Harvey
Beacon Falls, CT

On Mon, 20 Aug 2007 09:21:30 -0000, satish
<satishkumar.gourabathina [at] gmail.com> wrote:

>HI,
>I have a table
>Create table test(a int identity(1,1), b int)
>insert into test(b) values(12)
>insert into test(b) values(30)
>insert into test(b) values(65)
>insert into test(b) values(78)
>insert into test(b) values(36)
>
>o/p
>a b
>1 12
>2 30
>3 65
>4 78
>5 36
>
>i need to copy the table into another table with creating the new
>table
>we had a option
>select * into newtable from oldtable
>here the data in the oldtable will e copied to new table without
>creating new table
>but i need to copy the data as shown below with out creating new
>table
>o/p
>a b
>11 12
>12 30
>13 65
>14 78
>15 36
>
>Thanks,
>Satish
Roy Harvey [ Mo, 20 August 2007 15:09 ] [ ID #1799815 ]

Re: Copy data from one table to another table with change in identity column values

Roy Harvey (roy_harvey [at] snet.net) writes:
> If I understand your question, you want to insert the data from table
> test into an already existing table.
>
> INSERT existingtable
> SELECT a, b
> FROM test

I guess it should be:

INSERT existingtable
SELECT 10 + a, b
FROM test

since Salish wanted to change the values.


--
Erland Sommarskog, SQL Server MVP, esquel [at] sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downlo ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books .mspx
Erland Sommarskog [ Mo, 20 August 2007 23:54 ] [ ID #1799848 ]

Re: Copy data from one table to another table with change in identity column values

On Mon, 20 Aug 2007 21:54:50 +0000 (UTC), Erland Sommarskog
<esquel [at] sommarskog.se> wrote:

>since Salish wanted to change the values.

Thanks for catching that, Erland.

Roy
Roy Harvey [ Di, 21 August 2007 00:06 ] [ ID #1799850 ]
Datenbanken » comp.databases.ms-sqlserver » Copy data from one table to another table with change in identity column values

Vorheriges Thema: MS SQL copy new and modified rows from TABLE1 to TABLE2
Nächstes Thema: SQL Profiler - SPID