DCDBA (7/31/2009)
How about this:CREATE FUNCTION dbo.fGetDateTimeString
(
@dt datetime
)
RETURNS varchar(12)
AS
BEGIN
RETURN Convert(varchar(8), @dt, 112) + Replace(Convert(varchar(5), @dt, 114), ':', '')
END
DCDBA is the winner.
I ran the original code vs the modified code. There are a total of 12 steps and when looking at the execution plan each step takes 8.333% of the execution time (100 / 12).
So 8.333 * 11 = 91.663% for the original
vs.
8.334% for the modified.
It appears the author needs to press F1 and look up the CONVERT funciton.
--Paul Hunter