SQL Stored Porcedure/Output Text File

I am trying to create a SQL Stored procedure that will create a report on a nightly bases.  
The requirement for the file name is mrpt.mmddyyyyhhmm.txt  
I need to have my stored procedure name the file this way so that no one has to touch it manually.  
The best I have been able to get is it naming the file mrpt.mmd (the mmd sets as the extension of the file and it cannot be opened).  
Thank you in advance for any help with this issue.
Who is Participating?
tsnironeConnect With a Mentor Commented:
So for the filename it should be something like:

declare @TheDate datetime

set @TheDate = GetDate()



+ right('0' + convert(varchar,datepart(Month,@TheDate)), 2) --The Month

+ right('0' + convert(varchar,datepart(Day,@TheDate)), 2) --The Day

+ convert(varchar,datepart(Year,@TheDate)) --For the Year

+ right('0' + convert(varchar,datepart(hour,@TheDate)), 2) --The hour

+ right('0' + convert(varchar,datepart(minute,@TheDate)), 2) --The minute

+ '.txt'
I would like to have some more clarification on your query.
1. Is the idea just to create a txt file on the local system or to even mail it?
2. I did not get your naming convention for the file - mrpt.mmddyyyyhhmm.txt What does "mrpt" here. Is this a fixed hardcoded value of something dynamic?
If you want something very static, please try this tsql -
DECLARE @DateSeparator AS CHAR(1) = '/'
SELECT 'mrpt.'+ 

Open in new window

smc1234Author Commented:
Thanks a lot :)
Question has a verified solution.

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.

All Courses

From novice to tech pro — start learning today.