Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Copy from Excel file into SQL table using BCP Expand / Collapse
Author
Message
Posted Tuesday, March 4, 2014 2:02 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, March 22, 2014 7:55 AM
Points: 25, 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
Post #1547552
Posted Tuesday, March 4, 2014 2:15 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:54 PM
Points: 13,735, Visits: 10,705
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?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1547558
Posted Tuesday, March 4, 2014 3:03 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 3:39 PM
Points: 37,101, Visits: 31,653
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1547582
Posted Tuesday, March 4, 2014 3:15 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:54 PM
Points: 13,735, Visits: 10,705
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?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1547584
Posted Friday, March 7, 2014 6:53 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, March 22, 2014 7:55 AM
Points: 25, 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
Post #1548719
Posted Friday, March 7, 2014 7:01 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 1:54 PM
Points: 13,735, Visits: 10,705
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?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1548724
Posted Friday, March 7, 2014 5:03 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Today @ 3:39 PM
Points: 37,101, Visits: 31,653
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."

(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1548931
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse