﻿-- =============================================
-- Author:		S.E.Locatelli
-- Create date: 2013.11.28
-- Description:	Conversione datetime da yyyyMMddHHmmssnn
-- =============================================
CREATE FUNCTION f_dtFromRaw 
(
	-- Add the parameters for the function here
	@origDt nvarchar(50)
)
RETURNS datetime
AS
BEGIN
	DECLARE @output datetime
	DECLARE @strDt NVARCHAR(50)

	SELECT	@strDt = LEFT(@origDt, 4) + '-' + SUBSTRING(@origDt, 5,2 ) + '-' + SUBSTRING(@origDt, 7,2 ) + ' ' + SUBSTRING(@origDt, 9,2 ) + ':' + SUBSTRING(@origDt, 11,2 ) + ':' + SUBSTRING(@origDt, 13,2 ) + '.' + SUBSTRING(@origDt, 15,2 ) +'0'

	SELECT	@output = CONVERT(DATETIME, @strDt, 121)

	RETURN @output

END
