SQL Dinamicamente ( En Run-Time )

02/05/2004 - 17:19 por Mario Reiley | Informe spam
Al tratar de crear dinamicamente el siguiente SQL, el servidor me arroja
este error:

Error de sintaxis al convertir una cadena de caracteres a datetime

este es el SQL:

set @sql = N'SELECT htDetalleNormal.Lun, htDetalleNormal.Mar,
htDetalleNormal.Mie, htDetalleNormal.Jue, htDetalleNormal.Vie,
htDetalleNormal.HojaId, ' +
'htDetalleNormal.FechaMie AS Desde, htDetalleNormal.FechaMie AS Hasta
' +
'FROM personal FULL OUTER JOIN ' +
'Clasificacion ON personal.ClasificacionId Clasificacion.ClasificacionId FULL OUTER JOIN ' +
'Hojatiempo ON personal.CedulaId = Hojatiempo.CedulaId FULL
OUTER JOIN ' +
'htDetalleNormal ON Hojatiempo.HojaId = htDetalleNormal.HojaId '
+
'WHERE ' + (COL_NAME(OBJECT_ID('dbo.HtDetalleNormal'),@Desde) + ' >= ' +
CONVERT(DATETIME,@FDesde, 102)) + 'AND ' +
(COL_NAME(OBJECT_ID('dbo.HtDetalleNormal'),@Hasta) + ' <= ' +
CONVERT(DATETIME,@FHasta, 102)) + ' for browse'

Gracias de antemano.

Mario
 

Leer las respuestas

#1 Juan Carlos Leguizamón
02/05/2004 - 21:54 | Informe spam
Prueba agregando un RTRIM a los CONVERT(DATETIME,@Fxxx, 102))

"Mario Reiley" escribió en el mensaje
news:
Al tratar de crear dinamicamente el siguiente SQL, el servidor me arroja
este error:

Error de sintaxis al convertir una cadena de caracteres a datetime

este es el SQL:

set @sql = N'SELECT htDetalleNormal.Lun, htDetalleNormal.Mar,
htDetalleNormal.Mie, htDetalleNormal.Jue, htDetalleNormal.Vie,
htDetalleNormal.HojaId, ' +
'htDetalleNormal.FechaMie AS Desde, htDetalleNormal.FechaMie AS


Hasta
' +
'FROM personal FULL OUTER JOIN ' +
'Clasificacion ON personal.ClasificacionId > Clasificacion.ClasificacionId FULL OUTER JOIN ' +
'Hojatiempo ON personal.CedulaId = Hojatiempo.CedulaId FULL
OUTER JOIN ' +
'htDetalleNormal ON Hojatiempo.HojaId = htDetalleNormal.HojaId


'
+
'WHERE ' + (COL_NAME(OBJECT_ID('dbo.HtDetalleNormal'),@Desde) + ' >= '


+
CONVERT(DATETIME,@FDesde, 102)) + 'AND ' +
(COL_NAME(OBJECT_ID('dbo.HtDetalleNormal'),@Hasta) + ' <= ' +
CONVERT(DATETIME,@FHasta, 102)) + ' for browse'

Gracias de antemano.

Mario


Preguntas similares