Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Error "Conversion failed when converting date and/or time from character string" to execute one query in sql 2008 r2, run ok in 2005.

$
0
0

I have  a table-valued function that run in sql 2005 and when try to execute in sql 2008 r2, return the next "Conversion failed when converting date and/or time from character string".

USE [Runtime]
GO
/****** Object:  UserDefinedFunction [dbo].[f_Pinto_Graf_P_Opt]    Script Date: 06/11/2013 08:47:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE   FUNCTION [dbo].[f_Pinto_Graf_P_Opt] (@fechaInicio datetime, @fechaFin datetime)  

-- Declaramos la tabla "@Produc_Opt" que será devuelta por la funcion

RETURNS @Produc_Opt table ( Hora datetime,NSACOS int, NSACOS_opt int)

AS  
BEGIN 

-- Crea el Cursor

DECLARE cursorHora CURSOR
READ_ONLY
FOR SELECT DateTime, Value FROM f_PP_Graficas ('Pinto_CON_SACOS',@fechaInicio, @fechaFin,'Pinto_PRODUCTO')

-- Declaracion de variables locales

DECLARE @produc_opt_hora int
DECLARE @produc_opt_parc int
DECLARE @nsacos int
DECLARE @time_parc datetime

-- Inicializamos VARIABLES

SET @produc_opt_hora = (SELECT * FROM f_Valor (@fechaFin,'Pinto_PRODUC_OPT'))

-- Abre y se crea el conjunto del cursor

OPEN cursorHora

-- Comenzamos los calculos 

FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos

/*****************************************************************************/
/************  BUCLE WHILE QUE SE VA A MOVER A TRAVES DEL CURSOR  ************/
/*****************************************************************************/

WHILE (@@fetch_status <> -1)
BEGIN
IF (@@fetch_status = -2)
BEGIN
-- Terminamos la ejecucion 
BREAK
END
-- REALIZAMOS CÁLCULOS

SET @produc_opt_parc = (SELECT dbo.f_P_Opt_Parc (@fechaInicio,@time_parc,@produc_opt_hora))

-- INSERTAMOS VALORES EN LA TABLA

INSERT @Produc_Opt VALUES (@time_parc,@nsacos, @produc_opt_parc)

-----------------------------------------------------------------------
-- Avanzamos el cursor

FETCH NEXT FROM cursorHora INTO @time_parc,@nsacos
END

/*****************************************************************************/
/************  FIN DEL BUCLE QUE SE MUEVE A TRAVES DEL CURSOR  ***************/
/*****************************************************************************/

-- Cerramos el cursor

CLOSE cursorHora

-- Liberamos  los cursores

DEALLOCATE cursorHora

RETURN 

END


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>