Copy from Excel file into SQL table using BCP

  • 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

  • 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).

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • 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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • 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.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • 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

  • 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.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • 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.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply