Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Location
    Bangalore, India
    Posts
    27

    Lightbulb Unanswered: BCP Once again...

    I have to output into an external file for more than one query out put. Presently what i am doing is :-

    bcp "SELECT l.Name, j.Name FROM msdb..sysjobs j INNER JOIN master..syslogins l ON l.sid = j.owner_sid" queryout %5\\JOBS.xls -c -S%1 -U%3 -P %4

    bcp "select l.name from master..syslogins l with (nolock) inner join %2..tbluser j on l.name = j.tloginname" queryout %5\\SQLUSERS.xls -c -S%1 -U%3 -P %4

    The above are the two queries and i export into two different excel files.

    Is there any way i can append the second select query data into the already created excel file???

    --Sandu

  2. #2
    Join Date
    Sep 2003
    Posts
    522
    i don't think you can do it straight from bcp, but you can add a third line to your batch file:

    copy first_file.xls + second_file.xls third_file.xls

  3. #3
    Join Date
    Oct 2003
    Location
    Bangalore, India
    Posts
    27

    Thumbs up

    Originally posted by ms_sql_dba
    i don't think you can do it straight from bcp, but you can add a third line to your batch file:

    copy first_file.xls + second_file.xls third_file.xls
    That was cool solution...

    Now a few more questions :-)

    1. Can i give any spacing between the first and second file data in the third file??? Or can i give any heading before the data of the first and the second file???

    2. After copying the data into the third file how can i delete the first and the second file through the batch file???

    --Sandu_Bangalore

  4. #4
    Join Date
    Sep 2003
    Posts
    522
    1. echo. >> third_file.xls

    2. del first_file.xls & del second_file.xls

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •