Become a Premium Member and unlock a new, free course in leading technologies each month.
Go Premium for a chance to win a PS4. Enter to Win
declare @qry varchar(8000)
declare @column1name varchar(50)
-- Create the column name with the instrucation in a variable
SET @Column1Name = '[sep=,' + CHAR(13) + CHAR(10) + 'customerid]'
-- Create the query, concatenating the column name as an alias
select @qry='set nocount on;select customerid ' + @column1name +
' ,companyname, contactname, country from customers'
-- Send the e-mail with the query results in attach
exec msdb.dbo.sp_send_dbmail @recipients="Your email",
@attach_query_result_as_file = 1,
@query_attachment_filename = 'result.csv',
Open in new window
We value your feedback.
Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
If i do not want to use sql agent to schedule, what can i do?
Gentlemen - Please refrain from posting links-only or links-mostly answers. Thanks in advance.
Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.
Join & Ask a Question
Join our community for more solutions or to ask questions.
For immediate help use Live now!