Thursday, December 4, 2014

How to add Date and Time to output file for Jobs

In one of my project I  come across this requirement that setup a job to run every hour and the output must have a Date and Time.

I found couple of solutions

1. When using SQLServer Management Studio(SSMS) you can add below syntax for output file

SSMS--> SQL Server Agent --> Job Name--> Properties --> Steps --> Select "edit" -->  Advanced 

$(ESCAPE_SQUOTE(DATE))_$(ESCAPE_SQUOTE(TIME))

For exL:-
D:\SQLBackup\ouput_file$(ESCAPE_SQUOTE(DATE))_$(ESCAPE_SQUOTE(TIME)).txt

2.  Use Tokens in Job setup

Refer below MSDN doc
http://msdn.microsoft.com/en-us/library/ms175575.aspx

3. use %date% format with sqlcmd

for ex:-
sqlcmd -S sqlserver,port -U <user> -P <password>  -i "c:\query.sql" -o "c:\ouput_%date%.txt"

You can play around %date% format if you are looking for specific date format.

Regards
Satishbabu Gunukula

10 comments:

  1. Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject. שרת וירטואלי

    ReplyDelete
  2. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.. targonca szállítás Debrecen Europa-Road Kft

    ReplyDelete
  3. Wow, cool post. I'd like to write like this too - taking time and real hard work to make a great article... but I put things off too much and never seem to get started. Thanks though. 熊猫VPN

    ReplyDelete
  4. 免费VPN companies should not be keeping log files, and all of them claim that they don’t. However, many still do, which is why it’s important to do your research.

    ReplyDelete
  5. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. textbook answers

    ReplyDelete
  6. While they might imagine that everything on the server is firmly monitored a Blind SQL infusion assault will quietly be playing truth or outcomes with the web server. https://onohosting.com/

    ReplyDelete
  7. Your draftsman ought to likewise have insight in database standardization so your plan will follow the accepted procedures for social databases. Information demonstrating is likewise an ability your engineer ought to have. https://hostinglelo.in/

    ReplyDelete
  8. I exploit solely premium quality products -- you will observe these individuals on: 900 seconds into minutes

    ReplyDelete
  9. Test banks created by educators are often used in conjunction with other assessment tools, such as quizzes and exams.

    ReplyDelete