Hi Team,
With the help of below code i am able to send csv file on email.
Please help me with formatting the csv file through bcp.
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",
@query=@qry,
@subject='Client list',
@attach_query_result_as_file = 1,
@query_attachment_filename = 'result.csv',
@query_result_separator=',',@query_result_width =32767,
@query_result_no_padding=1