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!
-AllaGood luck. I've never been able to pull this off.
没有评论:
发表评论