TheBugSlayer
Programmer
Good day all. I need some quick help optimizing the date time manipulation in this query. The query is the most time-consuming in a very long script...I want to take it out by saving the resultset in a temp table then join the rest of the query to the temp table. MyTable is a very dense table.
Thanks much.
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)
Code:
--SELECT CONVERT(VARCHAR(10), DATEADD(D, -1, GETDATE()), 101) --Yields date in format '12/12/2010'
--ReportDateTime is in format '20101212231715'
SELECT * FROM dbo.MyTable WITH (NOLOCK)
WHERE SUBSTRING(ReportDateTime,5,2) + '/'
SUBSTRING(ReportDateTime,7,2) + '/' +
SUBSTRING(ReportDateTime,1,4) = CONVERT(VARCHAR(10), DATEADD(D, -1, GETDATE()), 101)
Thanks much.
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA)