Archive for 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.

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.

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

VN:F [1.9.22_1171]
Rating: 9.9/10 (7 votes cast)
VN:F [1.9.22_1171]
Rating: -1 (from 1 vote)

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?


--

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()))

--

Answer:

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

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

Try CONVERT.

--

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

--

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

VN:F [1.9.22_1171]
Rating: 9.9/10 (12 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)
`