bcp with queryout

  • Can someone tell me what is wrong with this bcp statement?

    bcp "SELECT s.banner, h.hostname FROM service s, host h where checkbyte = 0" queryout "DataProducts.txt" -c -SMAZZY -dCometDB -Usa -Ppassword

    I need to write a stored procedure that will be called by an application and only bcp the rows that have checkbyte = 0.

  • Can you post the error returned?

    I Don't see any where condition for the join.

    Execute the select without using bcp, to check that returns any results, and also that it is what you espect to bco out.

    I would suggest to use a full path to specify the output file, because if you run the bcp from the sp with xp_cmdshell, then it will create the file in the \winnt\system32 directory.Unless you specify the path.

  • I tried it a again:

    use master

    exec xp_cmdshell 'bcp "select * from dbname.owner.table where checkbit = 0" queryout e:\products.txt -c -Sserver -Usa -Ppassword'

    I get as an error the format for writing bcp commands...?

  • Thanks for your input I realized the problem...I had to also include the Dbname.table.columnname in the where clause..

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

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