Link to home
Start Free TrialLog in
Avatar of binaryman101
binaryman101Flag for United States of America

asked on

Simple Export SQL 2005 View to a email CSV file

I have a SQL script that I would like to send the file in CSV instead of TXT  I have attached the following code.  Am asking it to do something that it can not do?
EXEC msdb.dbo.sp_send_dbmail
 
@profile_name = 'U4 Notifications.com'
,@recipients = 'test@test.com'
,@subject = 'Circuits missing a CLLI Code - Process Z4026 - "Garbage man cometh"'
,@attach_query_result_as_file = 1
-- can go to 32767 for query width
,@query_result_width = 32767
,@body_format = 'TEXT'
,@body = 'blah blah blah test message
 
'
,@append_query_error = 0
,@exclude_query_output = 0
,@query_no_truncate = 0
,@query = 'SELECT ANI = Left(ANI,12) FROM [Billing Automation Processes].dbo.[Z4026 - Circuits missing CO information]'

Open in new window

Avatar of Marcjev
Marcjev
Flag of Belgium image

Directly simple answer... yes,
but, you can select a wide varchar line and make each line of the CSV yourselves.
Something like select convert(varchar(10),attrib1) + ',' + convert ... etc,
write it to a file and give it an explicit filename like @query_attachment_filename='fileout.csv'
Avatar of binaryman101

ASKER

I am a newbie to this, can you offer a little more step by step instructions?
ASKER CERTIFIED SOLUTION
Avatar of MonkeyPushButton
MonkeyPushButton
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Worked great!  Thanks.