OSQL Bulk Insert

  • How can I insert data from a pipe deli text file into a SQL table using OSQL. Please don't recommend BCP as I have used it before and want to try the OSQL for many reasons.

    I have got this osql statememnt for selecting data

    osql -UMyUser -PMyPassword -SMyServer -dMyDB -Q"Select * From User_Table"

    But how can I insert data from an external text file into the same table. It has two columns User_Name, User_Code

    text file sample

    Test1|AX123

    Test2|BX321

    help please....

  • I think that you can do it by running bulk insert command or using insert select statement with openrowset function and the bulk driver (you can read about both in BOL – Book on line that is installed with the client tools of SQL Server). I have to admit that I would do it with BCP. Any reason that you want to do it from command prompt but without BCP?

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • Hi Adi

    Thank you once again.

    I have used BCP for inserting data and it works fine. I hit the wall when I exec stored proc with BCP and got away with using OSQL. Now I thought of keeping the utils consistent just with OSQL insted of mixing with BCP and OSQL, just my thought....

    I think as you suggested, I might just use BCP command.....

    Thank you....

Viewing 3 posts - 1 through 3 (of 3 total)

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