Monthly Archives: February 2010

Re-Post: SQL Server and PowerShell WebCasts

I created a 2 part webcast on SQL Server and PowerShell last November/December, and I just wanted to re-post it in my site.

SQL Server PowerShell: Part I

Posted on November 25, 2009

Overview: This video is part 1 of a 2 part video series that goes through PowerShell basics with demonstrations on how to use PowerShell with SQL Server.

http://vimeo.com/moogaloop.swf?clip_id=7826965&server=vimeo.com&show_title=1&show_byline=0&show_portrait=0&color=00adef&fullscreen=1

SQL Powershell Part One authored by Donabel Santos (@sqlbelle) on Vimeo.

Author: @sqlbelle

Recorded On: 17″ MacBook Pro

Software: Telestream’s ScreenFlow

SQL Server PowerShell: Part II

Posted on December 3, 2009

Overview: This video is part 2 of a 2 part video series that demonstrates how to use PowerShell with SQL Server, using the SSMS built-in mini shell, and using .NET and SMO.

http://vimeo.com/moogaloop.swf?clip_id=7855533&server=vimeo.com&show_title=1&show_byline=0&show_portrait=0&color=ff9933&fullscreen=1

SQL Powershell Part Two Donabel Santos (@sqlbelle) on Vimeo.

Created for the Edmonton PASS user group by Donabel Santos at Black Ninja Software.

Author: @sqlbelle
Recorded On: 17″ MacBook Pro
Software: Telestream’s ScreenFlow

Advertisements

Refactor This: Runaway T-SQL to Print YYMMDD

Recently trying to debug some really cryptic T-SQL scripts.

Guess what this is trying to do?

[sql collapse=”false” firstline=”1″ gutter=”true” smarttabs=”true” tabsize=”4″ toolbar=”true”]

DECLARE @dt varchar(6)
SET @dt = RIGHT(CONVERT(varchar(4), YEAR(getdate())),2) + REPLICATE(‘0’, 2 – LEN(CONVERT(varchar(2), MONTH(getdate())))) + CONVERT(varchar(2), MONTH(getdate())) + REPLICATE(‘0’, 2 – LEN(CONVERT(varchar(2), DAY(getdate())))) + CONVERT(varchar(2), DAY(getdate()))

[/sql]

Answer:

It’s trying to print the current date in YYMMDD format.

Uhm, there’s a much better way to do this.

Try CONVERT.

[sql collapse=”false” firstline=”1″ gutter=”true” smarttabs=”true” tabsize=”4″ toolbar=”true”]

SET @dt = CONVERT(VARCHAR(6), GETDATE(), 12)


[/sql]

I still quite enjoy debugging or refactoring T-SQL scripts, but sometimes I’m just amazed at what I still see …