SQL En Visual
Tengo que consultar en una tabla entre fechas y los unico que me dice es que no hay datos y los hay, haber si me pueden ayudar a corregir el código fuente, porfavor. la fecha la tengo declarada como caracter
sel = "(SELECT * FROM Prestamo WHERE fecha_prestamo BETWEEN " &text1 & " and " & text2 & ")"
sel = "(SELECT * FROM Prestamo WHERE fecha_prestamo BETWEEN " &text1 & " and " & text2 & ")"
EL problema es que estás pasando las fechas de forma errónea. La solución sería:
sel = "SELECT * FROM Prestamo WHERE fecha_prestamo BETWEEN datevalue('" &text1 & "') and datevalue('" & text2 & "')"
también puedes usar la forma:
sel = "(SELECT * FROM Prestamo WHERE fecha_prestamo BETWEEN #" &text1 & "# and #" & text2 & "#)"
Pero a mí me gusta más la primera, evita errores con diferentes configuraciones regionales.
Saludos
sel = "SELECT * FROM Prestamo WHERE fecha_prestamo BETWEEN datevalue('" &text1 & "') and datevalue('" & text2 & "')"
también puedes usar la forma:
sel = "(SELECT * FROM Prestamo WHERE fecha_prestamo BETWEEN #" &text1 & "# and #" & text2 & "#)"
Pero a mí me gusta más la primera, evita errores con diferentes configuraciones regionales.
Saludos
