T-SQL Tuesday #1: Date/Time Tricks

SQL Server 2005, SQL Server 2008, SQLServerPedia Syndication, TSQL
I'm going to try out Adam Machanic's idea for a blog party. The topic this month are Date/Time tricks. Instead of supplying a trick for Date/Time, I'm going to caution you about the tricks that you use. Let's takeĀ a simple issue. You want to pull back data from a table, let's use the Production.TransactionHistoryArchive in AdventureWorks2008, for a given month of data. Before we run the query, let's create an index on the table: [crayon-5a6c3b3479d2a562143452/] The query itself is pretty simple. This is one mechanism that will retrieve the data for the month of July in 2003: [crayon-5a6c3b3479d35373577712/] In theory you should be able to use the index that was created earlier, but instead, you'll see this execution plan: The problem is occuring because there is a function running against…
Read More