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.
| Author |
Topic |
|
shravanigonela
Starting Member
2 Posts |
Posted - 2009-03-09 : 03:23:30
|
| hi, i am new to sql server, .............i have 2 databases,i have to insert data from the old database to new database........for example i have first_name column in new database but i have first_name,first_name1,first_name2 ... 3 columns in old database...... i have to insert 3 columns into the 1 column in new database.......i have done like this .......1. In the dataflow task i have taken oledb source in which i have selected 3 columns and sorted it...2.on the side taken another oledb1 source which have 1 column first_name and sorted.....what should i do to insert 3 colums in to the one column.........please help me urgently........... |
|
|
guptam
Posting Yak Master
161 Posts |
Posted - 2009-03-09 : 03:36:46
|
| Are both databases on same server?If so you can do ...INSERT INTO NewDBName.dbo.Table (First_Name) SELECT first_name FROM OldDB.dbo.TableINSERT INTO NewDBName.dbo.Table (First_Name) SELECT first_name1 FROM OldDB.dbo.TableINSERT INTO NewDBName.dbo.Table (First_Name) SELECT first_name2 FROM OldDB.dbo.Table-- Mohit K. GuptaB.Sc. CS, Minor JapaneseMCITP: Database AdministratorMCTS: SQL Server 2005http://sqllearnings.blogspot.com/ |
 |
|
|
matty
Posting Yak Master
161 Posts |
Posted - 2009-03-09 : 04:27:42
|
| INSERT INTO NewDB.dbo.Table (First_Name) SELECT first_name + ' ' + first_name1 + ' ' + first_name2 FROM OldDB.dbo.Table |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-03-09 : 07:15:29
|
| just modification to matty querytry like thisSELECT ISNULL(first_name ,'') + ' ' + ISNULL(first_name1,'')+ ' ' + ISNULL(first_name2,'') FROM OldDB.dbo.TableSELECT COALESCE(first_name ,'') + ' ' + COALESCE(first_name1,'')+ ' ' + COALESCE(first_name2,'') FROM OldDB.dbo.Tableto avoids nulls when concatenating the varchar fields |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-10 : 02:39:38
|
or did you meant this?INSERT INTO NewDB.dbo.Table (First_Name) SELECT first_name FROM OldDB.dbo.TableUNIONSELECT first_name1 FROM OldDB.dbo.TableUNIONSELECT first_name2 FROM OldDB.dbo.Table |
 |
|
|
|
|
|
|
|