September 9, 2012 | SQL Server

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
 

4 comments on this post

    • Steve Morris - September 10, 2012, 1:58 PM

      even easier use Job Tokens :-
      http://msdn.microsoft.com/en-us/library/ms175575(v=sql.105).aspx

    • AaronBertrand - September 10, 2012, 11:10 PM

      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. 🙂

    • Zuzana - September 11, 2012, 1:28 AM

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

    • AaronBertrand - September 11, 2012, 3:56 PM

      Thanks Zuzana!

Comments are closed.