June 22, 2017 at 9:18 am
Hello,
I am sending a CSV file through sp_sebd_dbmail which contains couple of date datatype. But, when i look at the CSV file date is not formatted. Is there any way i can get the formatted date?
Thanks for your help in advance.
Query:
declare @qry varchar(8000)
declare @column1name varchar(50)
SET @Column1Name = '[sep=,' + CHAR(13) + CHAR(10) + 'BatchID]'
-- Create the query, concatenating the column name as an alias
select @qry='set nocount on;select BatchID ' + @column1name +
' ,UserName,FQFilename,
DateDownloaded,DateCreated,Type,IsLocked,DateInitiated
FROM table
WHERE DateDownloaded IS NULL
ORDER BY DateCreated DESC'
-- Send the e-mail with the query results in attach
exec msdb.dbo.sp_send_dbmail
--@profile_name = 'SRVSQLMON',
@Recipients='xxx@xyz.com',
@query=@qry,
@subject='Test Result',
@attach_query_result_as_file = 1,
@query_attachment_filename = 'result.csv',
@query_result_separator=',',@query_result_width =32767,
@query_result_no_padding=1
June 22, 2017 at 9:44 am
Never mind. I found the solution.
Updated the query using covnert function:
select @qry='set nocount on;select BatchID ' + @column1name +
' ,UserName,FQFilename,
CONVERT(VARCHAR(20),DateDownloaded,20) as DateDownloaded,
CONVERT(VARCHAR(20),DateCreated,20) As DateCreated,Type,IsLocked,
CONVERT(VARCHAR(20),DateInitiated,20) as DateInitiated
FROM table
WHERE DateDownloaded IS NULL
ORDER BY DateCreated DESC'
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy