Entre 2 fechas, error

31/05/2005 - 06:03 por humberto gonzalez | Informe spam
teniendo una tabla de ventas, porque cuando yo hago:

select * from viewcomis2 where fecha between '27/05/2005' and
'30/05/2005'

me aparecen resultados:

27/05/2005
28/04/2005 <-- este no deberia estar en el query.
28/05/2005
30/05/2005

lo resolvi:

((substring(fecha,1,2)) >= (substring('" & DTPicker1.Value & "',1,2)) and
(substring(fecha,4,2)) >= (substring('" & DTPicker1.Value & "',4,2)) and
(substring(fecha,7,4)) >= (substring('" & DTPicker1.Value & "',7,4))) AND
((substring(fecha,1,2)) <= (substring('" & DTPicker2.Value & "',1,2)) and
(substring(fecha,4,2)) <= (substring('" & DTPicker2.Value & "',4,2)) and
(substring(fecha,7,4)) <= (substring('" & DTPicker2.Value & "',7,4)))

pero aun me queda la duda: 27-05-2005 >= 27-04-2005 ?

creo que el query se hace muy lento de esta manera, no se me ocurrio nada
mejor ya que en todas las demas opciones se metia el 27-04-2005 (y en
otras el 28-04-2005 y otras fechas del mes 04)

aun asi sigo sin entender el porque de este error.

ah-> fecha es resultado de convert(char(10),dbo.venta.fecha,103) as Fecha
 

Leer las respuestas

#1 Salvador Ramos
31/05/2005 - 11:26 | Informe spam
Hola, utiliza siempre el formato ANSI y evitarás muchos problemas:
select * from viewcomis2 where fecha between '20050527' and '20050530'
También te paso un par de links interesantes sobre el tema:
http://www.helpdna.net/bosqlfaq05.htm
http://www.configuracionesintegrale...articulo%1

Un saludo
Salvador Ramos
Murcia - España
[Microsoft MVP SQL Server]
www.helpdna.net (información sobre SQL server, Windows DNA y .NET)

"humberto gonzalez" escribió en el mensaje
news:
teniendo una tabla de ventas, porque cuando yo hago:

select * from viewcomis2 where fecha between '27/05/2005' and
'30/05/2005'

me aparecen resultados:

27/05/2005
28/04/2005 <-- este no deberia estar en el query.
28/05/2005
30/05/2005

lo resolvi:

((substring(fecha,1,2)) >= (substring('" & DTPicker1.Value & "',1,2)) and
(substring(fecha,4,2)) >= (substring('" & DTPicker1.Value & "',4,2)) and
(substring(fecha,7,4)) >= (substring('" & DTPicker1.Value & "',7,4))) AND
((substring(fecha,1,2)) <= (substring('" & DTPicker2.Value & "',1,2)) and
(substring(fecha,4,2)) <= (substring('" & DTPicker2.Value & "',4,2)) and
(substring(fecha,7,4)) <= (substring('" & DTPicker2.Value & "',7,4)))

pero aun me queda la duda: 27-05-2005 >= 27-04-2005 ?

creo que el query se hace muy lento de esta manera, no se me ocurrio nada
mejor ya que en todas las demas opciones se metia el 27-04-2005 (y en
otras el 28-04-2005 y otras fechas del mes 04)

aun asi sigo sin entender el porque de este error.

ah-> fecha es resultado de convert(char(10),dbo.venta.fecha,103) as Fecha

Preguntas similares