Need to edge out the competition for your dream job? Train for certifications today.
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
Your question, your audience. Choose who sees your identity—and your question—with question security.
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.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.