Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2006
    Posts
    31

    Unanswered: BCP -- Formatting Output

    Hi,

    I wrote the below code and procedure that exports two tables contents into 2 separate Excel files. Is there a way to export contents of two tables via BCP utility into 1 Excel file but 2 different Worksheets of this file?

    DECLARE @FileName varchar(50),
    @FileName1 varchar(50),
    @bcpCommand varchar(2000)
    SET @FileName = 'E:\GPPD_db_stats.XLS'
    SET @FileName1 = 'E:\GPPD_file_stats.XLS'
    print @FileName
    SET @bcpCommand = 'bcp "master.dbo.spdbdesc" OUT ' + @FileName + ' -Samex-srv-gppdb -T -c'
    print @bcpCommand
    EXEC master..xp_cmdshell @bcpCommand

    SET @bcpCommand = 'bcp "master.dbo.spfiledesc" OUT ' + @FileName1 + ' -Samex-srv-gppdb -T -c'
    print @bcpCommand
    EXEC master..xp_cmdshell @bcpCommand
    exec master.dbo.xp_stopmail
    set @bcpCommand = ' ' + @FileName + '; ' + @FileName1 + ''
    DECLARE @body VARCHAR(1024)
    SET @body = 'Please find enclosed files with the database status reports as of '+
    CONVERT(VARCHAR, GETDATE()) + '. Please DO NOT respond to this email or the ones coming in the future ' +
    'with data files as this email address is not monitored for incoming emails. However, if you have any ' +
    'questions/concerns please contact ....'


    EXEC master..xp_sendmail
    @recipients='alla.levit@amex.com',
    @message = @body,
    @subject = 'Database Weekly Statistics Report',
    @attachments = @bcpCommand

    Thanks in advance!
    -Alla

  2. #2
    Join Date
    Dec 2002
    Location
    Sunny Florida
    Posts
    121
    Good luck. I've never been able to pull this off.

Posting Permissions

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