I have a UDF that goes like this:
CREATE FUNCTION [dbo].[funcGetDateFromFileName] (@filename varchar(50)) RETURNS datetime AS BEGIN DECLARE @extracteddate varchar(50) SET @extracteddate = SUBSTRING(@filename, 8, 10) RETURN CAST(@extracteddate AS datetime) END
When I call it in QA as per follows:
SELECT dbo.funcGetDateFromFileName('7HFCFM 16-05-2006_10;20;23_AM.MP3')
I get the following error message:
Server: Msg 242, Level 16, State 3, Procedure funcGetDateFromFileName, Line 7
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
I have looked at it, but I cannot see where the problem is. The Books Online documentation for CAST says that it SQL Server will do an implicit conversion from VARCHAR to DATETIME.
So, if anybody can help I would very much appreciate it.