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
 SQL Server Development (2000)
 Excel, SQL 2000 and VB6?

Author  Topic 

nightworlds
Starting Member

3 Posts

Posted - 2005-06-01 : 10:46:34
Hi

I need sql query that insert a bulk row of data from other database into another database.

I have two database (Excel and MSSQL2K) and on these databases I have different table and fields name.

Currently my VB6 Project used two connection(ADODB) and select and insert the data row by row from MS Excel into MSSQL2K.

I hope some body can save me into this slow setup of connection

Thanks!

--nightworlds--

AndyB13
Aged Yak Warrior

583 Posts

Posted - 2005-06-01 : 11:14:13
nightworlds
Excel is NOT a database and should never be treated as one!

Have a look at DTS in BOL

or there is this post from madhivanan, which might help

[url]http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926[/url]

Andy

Beauty is in the eyes of the beerholder
Go to Top of Page

raclede
Posting Yak Master

180 Posts

Posted - 2005-06-02 : 00:56:05
Excel --> Mssql have a Bulk Insert Command.. I've cut this from one of the post here, hope it helps.
But Mssql --> Excel see this forum http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50191

Apart from using DTS and Export wizard, we can also use this query to export data from SQL Server2000 to Excel

Create an Excel file named testing having the headers same as that of table columns and use this query

insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;',
'SELECT * FROM [SheetName$]') select * from SQLServerTable

To export data from Excel to new SQL Server table,

select *
into SQLServerTable FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;HDR=YES',
'SELECT * FROM [Sheet1$]')

To export data from Excel to existing SQL Server table,

Insert into SQLServerTable Select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;HDR=YES',
'SELECT * FROM [SheetName$]')


Exec Master..xp_cmdshell 'bcp "Select * from myTable" queryout "C:\testing.xls" -c'






"If the automobile had followed the same development cycle as the computer, a Rolls-Royce would today cost $100, get a million miles per gallon, and explode once a year, killing everyone inside. "

raclede
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-02 : 02:40:26
quote:

Exec Master..xp_cmdshell 'bcp "Select * from myTable" queryout "C:\testing.xls" -c'



nightworlds
I dont prefer this method as bcp is used to export to text file only
Use the previous methods



Madhivanan

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

- Advertisement -