Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 How to insert data from on etable to another

Author  Topic 

David Lopez
Starting Member

19 Posts

Posted - 2005-06-22 : 12:11:05
Hi, I am trying to copy data from an old(different) tabel to a new one. I am using
===
INSERT INTO Client(name)
VALUES mae_cli.name
FROM mae_cli
WHERE mae_cli.province = 'provinceNAME'
===
But it gives me errors.
The length of the camps are the same varchar(40).

Anybody with some help, I am new to this

Thx

David

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2005-06-22 : 12:38:52
Code
INSERT INTO Client(name)
VALUES (select column_name FROM mae_cli
WHERE mae_cli.province = 'provinceNAME')
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-23 : 01:41:53
quote:
Originally posted by afrika

Code
INSERT INTO Client(name)
VALUES (select column_name FROM mae_cli
WHERE mae_cli.province = 'provinceNAME')



Small Correction. Dont use Values
INSERT INTO Client(name)
(select name FROM mae_cli
WHERE mae_cli.province = 'provinceNAME')




Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

David Lopez
Starting Member

19 Posts

Posted - 2005-06-23 : 02:17:15
Thx all,

is there also a simple way to copy the data from the old DB to the new DB? BUT the amount/names of the colums aren´t the same!!
The old DB has about 40 columns and the new one has about 200 colums. Still I only need to copy the 40 columns into some 40 columns of the new DB. STILL, the names of the columns are different. Is there a simple way to do that????

It would really help me with my problem.

Many thx alrready

David
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-23 : 02:24:22
Insert into NewTable (col1,col2...col40)
Select col1,col2,..col40 from OldTable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

David Lopez
Starting Member

19 Posts

Posted - 2005-06-23 : 02:57:13
Thx,

but can I for example skip some colums from the first table (the new one), because some colums are new and don´t contain data?

something like

Insert into NewTable (col1,col5...col140)
Select col1,col32,..col99 from OldTable


many thx
Go to Top of Page

David Lopez
Starting Member

19 Posts

Posted - 2005-06-23 : 03:23:11
quote:
Originally posted by madhivanan

quote:
Originally posted by afrika

Code
INSERT INTO Client(name)
VALUES (select column_name FROM mae_cli
WHERE mae_cli.province = 'provinceNAME')



Small Correction. Dont use Values
INSERT INTO Client(name)
(select name FROM mae_cli
WHERE mae_cli.province = 'provinceNAME')




Madhivanan


Failing to plan is Planning to fail



Can you for example INSERT some columns with a combination of values and also SELECTS?
I Mean something like this:
===
INSERT INTO Clients(CodigoEmpresa, IdDelegacion, CodigoCliente, COD_LANG)
VALUES (9999, 'BAR', SELECT COD_CLI FROM OLD_TABLE, 'ES')
===

Go to Top of Page
   

- Advertisement -