xp_cmdshell for bulk import

  • I'm working on a stored procedure that I plan to use for importing a simple list from a text file. I pretty much have it figured out except that I'm getting extra information when I import the file using the bcp utility through xp_cmdshell. It displays the import information when the file is imported in addition to the items in the list. I just need to list the items imported and can ignore any other messages or errors.

    Here's a sample file that I'm importing.

    Item #1

    Item #2

    Item #3

    Item #3

    AND SO ON

    and the code I'm testing for the sp.

    USE [MYDB]

    GO

    IF OBJECT_ID('tempdb.dbo.tempList') IS NULL

    BEGIN

    CREATE TABLE tempdb.dbo.tempList (

    LISTTXT VARCHAR(30)

    );

    END

    GO

    SET NOCOUNT ON;

    EXEC master..xp_cmdshell 'bcp tempdb.dbo.tempList in \\mydb\LISTS\LIST.TXT -T -c '

    SELECT * FROM tempdb.dbo.tempList

    DROP TABLE tempdb.dbo.tempList

    output from the code

    output

    -----------------------------------------------------------------

    NULL

    Starting copy...

    NULL

    5 rows copied.

    Network packet size (bytes): 4096

    Clock Time (ms.) Total : 1 Average : (5000.00 rows per sec.)

    NULL

    LISTTXT

    ------------------------------

    Item #1

    Item #2

    Item #3

    Item #3

    AND SO ON

    Is it possible to suppress the output from the xp_cmdshell?

    Thanks

  • Are you seriously asking something that is clearly documented?

    http://technet.microsoft.com/en-us/library/ms175046.aspx

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I swear I've been googling 'no output' all day and couldn't find that.

    Thanks

  • Maybe I sound pedantic, but a good advice is to use the help included with SQL Server. Is as easy as pressing F1.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

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

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