THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Aaron Bertrand

Aaron is a Product Evangelist for SentryOne, makers of Plan Explorer and a performance monitoring and event management platform for the Microsoft Data Platform and VMware. He has been blogging here at since 2006, focusing on manageability, performance, and new features, and also blogs at and; has been a Microsoft MVP since 1997; tweets as @AaronBertrand; and speaks frequently at major conferences, user group meetings, and SQL Saturday events worldwide.

SQLSaturday #162 : Cambridge, England

Yesterday I presented at SQL Saturday #162. My slide deck and samples are here:

    Slide Deck & Samples: Bertrand - T-SQL Bad Habits & Best Practices

I also wanted to answer a question from an audience member after the session about how to generate YYYYMMDD strings to represent yesterday's date in order to append to a backup file name. In this case because we're probably not worried about performance (you're performing this calculation once), we can just use string conversion (see this blog post for a more detailed discussion about doing things like stripping time from datetime at high volume).

-- In SQL Server 2005, 2008 or 2008 R2, you can say:

SELECT [filename] = 'Backup' + CONVERT(CHAR(8), DATEADD(DAY, -1, GETDATE()), 112);

-- In SQL Server 2012, you can use a slightly more self-documenting method:

SELECT [filename] = 'Backup' + FORMAT(DATEADD(DAY, -1, GETDATE()), 'yyyyMMdd');

I was really impressed with how this event was run - it was super organized and I had a great time, so kudos to Mark and Lorraine Broadbent and everyone else who helped by speaking, volunteering and sponsoring.

Today I was able to take a walk around "The Backs" (the walkways along the river behind all the famous colleges here), then went to Castle Mound with Buck Woody & family, then Scott and I took a train to Ely to see the 4th largest cathedral in Europe. A good day. Pictures here:

    Cambridge | Ely

Published Sunday, September 9, 2012 6:08 PM by AaronBertrand



Steve Morris said:

even easier use Job Tokens :-

September 10, 2012 6:58 AM

AaronBertrand said:

Steve, sure, if all your code is listed out within the job step. If you're using more complicated logic you're probably using stored procedures and - especially if you need to call them outside the context of Agent as well - the tokens don't help much. :-)

September 10, 2012 4:10 PM

Zuzana said:

Thank you. It was a really great presentation. Will go and play with dates now.

September 10, 2012 6:28 PM

AaronBertrand said:

Thanks Zuzana!

September 11, 2012 8:56 AM
New Comments to this post are disabled

About AaronBertrand

...about me...

This Blog



Privacy Statement