Click here to Skip to main content
15,747,766 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have some of records in a table. I want that table records to generate csv file and that file send it to mail using sql server.

check this

sp_send_dbmail (Transact-SQL)

sample code

EXEC sp_send_dbmail @profile_name='default',

@query= 'SELECT [MID],[HID],[MeC],[LC],[RowCDate]
FROM [JBC].[dbo].[Table1] WHERE RowCDate >= GETDATE()
@query_attachment_filename = 'Results.csv',
@query_result_separator = ','
Share this answer
Shweta N Mishra 28-Nov-14 4:11am    
there is everything what you need, Should be able to convert it into your desired requirement. is it first time you are going to write a code for sending mail ?
(chaging the solution little bit , may work for you)

for converting it to csv there is no extra code written.

What you can do is the just a pass the parametr of seperator.

How about first converting it to csv and saving it. Look here.

Then you can read the saved file, attach and send mail. Look here

Share this answer
[no name] 28-Nov-14 4:06am    
code behind sql server. What does that mean ? Can you be a bit clear ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900