SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Copy from Excel file into SQL table using BCP


Copy from Excel file into SQL table using BCP

Author
Message
tracmonali
tracmonali
SSC Journeyman
SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)

Group: General Forum Members
Points: 93 Visits: 52
Hello, Is there a way to run a BCP utility to read excel file and copy into Sql table? I am aware of Import Export wizard but do not wish to use one. Can format files be used just how they are used to transfer flat files into sql table? How such bcp program be scheduled to be run at a certain time? Can we write SSIS package? Any help appreciated
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64468 Visits: 13298
I'm not sure you can read Excel with bcp (you can write to Excel with bcp though).
You can use FROM OPENROWSET to read an excel file, or just use SSIS (with is the same as the import wizard).


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)

Group: General Forum Members
Points: 221184 Visits: 42002
Koen Verbeeck (3/4/2014)
I'm not sure you can read Excel with bcp (you can write to Excel with bcp though).
You can use FROM OPENROWSET to read an excel file, or just use SSIS (with is the same as the import wizard).


I don't know of anyway that BCP can write to an Excel file. I know it can write to a CSV or TSV file, which Excel attaches and Excel icon to in Explorer, but it's not an actual Excel file. If you know of a way to write to an actual .xlsx or .xls file from BCP, I'm all ears. (and no... not being sarcastic... I've just never heard of such a thing and would like to learn the method if there's a way).

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64468 Visits: 13298
Jeff Moden (3/4/2014)
Koen Verbeeck (3/4/2014)
I'm not sure you can read Excel with bcp (you can write to Excel with bcp though).
You can use FROM OPENROWSET to read an excel file, or just use SSIS (with is the same as the import wizard).


I don't know of anyway that BCP can write to an Excel file. I know it can write to a CSV or TSV file, which Excel attaches and Excel icon to in Explorer, but it's not an actual Excel file. If you know of a way to write to an actual .xlsx or .xls file from BCP, I'm all ears. (and no... not being sarcastic... I've just never heard of such a thing and would like to learn the method if there's a way).


You're right. bcp can write to a .xls file, but it is actually just a .csv file behind the scenes.
Googling at this late hour had me jump to conclusions.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
tracmonali
tracmonali
SSC Journeyman
SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)SSC Journeyman (93 reputation)

Group: General Forum Members
Points: 93 Visits: 52
Thanks for information. Is there a way to write an SSIS which reads a table columns from one SQL server and transfers into another SQL server? I do not wish to use linked server. Can a query be used to join table columns across databases from 1 sql server and input as 1 table into db of 2nd sql server? Any thoughts appreciated
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64468 Visits: 13298
tracmonali (3/7/2014)
Thanks for information. Is there a way to write an SSIS which reads a table columns from one SQL server and transfers into another SQL server? I do not wish to use linked server. Can a query be used to join table columns across databases from 1 sql server and input as 1 table into db of 2nd sql server? Any thoughts appreciated


This question deserves a new topic, but anyway...
You can use a data flow for that. Put the query of server1 in the source, and write the results to server2.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)SSC Guru (221K reputation)

Group: General Forum Members
Points: 221184 Visits: 42002
tracmonali (3/7/2014)
Thanks for information. Is there a way to write an SSIS which reads a table columns from one SQL server and transfers into another SQL server? I do not wish to use linked server. Can a query be used to join table columns across databases from 1 sql server and input as 1 table into db of 2nd sql server? Any thoughts appreciated


Although there's no real performance penalty for joining across databases, there's a huge penalty for joining across databases on different servers. As Koen implied, the tables/data really need to be on 1 server and then you can push the data to another server much more quickly than doing a common join between tables on two different servers.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search