如何以CSV格式发送查询结果? [英] How to send a query result in CSV format?

查看:35
本文介绍了如何以CSV格式发送查询结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 ETL,我在 SSIS 包中的 SQL 任务中有以下 sql 代码.这就是我编码的方式.我正在从表中选择数据,并将该查询的结果作为文件.我希望以 CSV 格式发送此附件.我该怎么做?

I am working on ETL and I have this below sql code in my SQL Task in SSIS package. This is how i have coded. I am selecting a data from a table and result of that query as file. I want this attachment sent in CSV format. How do i do it?

EXEC sp_send_dbmail @profile_name='default',
@recipients='dev@null.com',
@subject=@SUB,
@body=@BODY,

@query= 'SELECT [MID],[HID],[MeC],[LC],[RowCDate]
FROM [JBC].[dbo].[Table1] WHERE RowCDate >= GETDATE()
',
@attach_query_result_as_file=1

任何帮助将不胜感激.提前致谢.

Any help will be very appreciated. Thanks in advance.

推荐答案

添加 @query_result_separator 应该可以解决问题.

Adding @query_result_separator should do the trick.

EXEC sp_send_dbmail @profile_name='default',
@recipients='dev@null.com',
@subject=@SUB,
@body=@BODY,

@query= 'SELECT [MID],[HID],[MeC],[LC],[RowCDate]
FROM [JBC].[dbo].[Table1] WHERE RowCDate >= GETDATE()
',
@attach_query_result_as_file = 1,
@query_attachment_filename   = 'Results.csv',
@query_result_separator      = ','

添加 @query_result_no_padding = 1 可能会稍微清理结果.可以在此处

Adding @query_result_no_padding = 1 might clean up the results a bit. All off the arguments can be found here

这篇关于如何以CSV格式发送查询结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆