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 2005 Forums
 Transact-SQL (2005)
 Mass Colum Data Transfer

Author  Topic 

Numbus
Starting Member

2 Posts

Posted - 2009-06-12 : 21:49:48
Hey all, I am new here and I been trying to figure this script out for a couple of days now. Trying to give it fresh looks but I just can't get it to work right.

I am trying to copy information out of an old Database into a new one. But I only want specific information. Now I did write a SQL Script for this but I only get errors. I cant seem to figure out why the Data from the Old DB colums (same structure and data format) arent being entered in the NEW Database.

This is the script I have now:
DECLARE @newaccount varchar(17);
DECLARE @name varchar(17);
DECLARE @newbase int;
DECLARE @newaccountid int;
DECLARE @oldserial int;

SET @newaccount = 'Characcount';
SET @name = 'Charname';
SET @newaccountid = CharID;
SET @oldserial = oldserial;

INSERT INTO Table FakeDB.dbo.tbl_base (DCK,Lock,Name,AccountSerial,Account,Slot,Race,Class,Lv,Dalant,Gold,BaseShape,EK0,EU0,EK1,EU1,EK2,EU2,EK3,EU3,EK4,EU4,EK5,EU5,EK6,EU6,EK7,EU7,LastConnTime,CreateTime,DeleteTime,DeleteName,FirstConnTime,HomeServer,Arrange,ES0,ET0,ES1,ET1,ES2,ET2,ES3,ET3,ES4,ET4,ES5,ET5,ES6,ET6,ES7,ET7)
SELECT DCK,Lock,@name,@newaccountid,@newaccount,Slot,Race,Class,Lv,Dalant,Gold,BaseShape,EK0,EU0,EK1,EU1,EK2,EU2,EK3,EU3,EK4,EU4,EK5,EU5,EK6,EU6,EK7,EU7,LastConnTime,CreateTime,DeleteTime,DeleteName,FirstConnTime,HomeServer,Arrange,ES0,ET0,ES1,ET1,ES2,ET2,ES3,ET3,ES4,ET4,ES5,ET5,ES6,ET6,ES7,ET7
FROM RF_World223fix.dbo.tbl_base
WHERE Serial = '@oldserial'


Oh I should mention that the records are already there in the new DB but empty. So same rows and colums but empty without data.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-14 : 02:07:38
if records are aleardy there you should be doing update rather than insert.

ie. something like

UPDATE t
SET t.DCK=c.DCK,
Lock=c.Lock,
Name=@name
.....
FROM FakeDB.dbo.tbl_base t
JOIN RF_World223fix.dbo.tbl_base c
ON t.comonfield=c.commonfield
Go to Top of Page

Numbus
Starting Member

2 Posts

Posted - 2009-06-14 : 13:36:20
Thank you for that. I took the long route around and use a retrivial command for each colum in the table. It's working now :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-14 : 14:45:10
cool
Go to Top of Page
   

- Advertisement -