consulta con fecha

23/11/2007 - 06:54 por Edgar Brito | Informe spam
Si alguien puede ayudarme con esto:

tengo una hoja de excel cuyos datos intento enviar a sql server 2005 asi que
utilizo ADO de la siguiente forma:

Dim Conexion As ADODB.Connection, CadenaConexion As String
Set Conexion = New ADODB.Connection
'CADENA DE CONEXION
Conexion.Open "Provider=SQLNCLI; " & _
"Initial Catalog=tesoreria; " & _
"Data Source=desktop; " & _
"integrated security=SSPI; persist security info=True;"

Dim MovBancarios As ADODB.Recordset
Set MovBancarios = New ADODB.Recordset
'DEL LADO DEL CLIENTE
MovBancarios.CursorLocation = adUseClient
MovBancarios.CursorType = adKeySet
'TRATO DE RECUPERAR LOS REGISTROS QUE COINCIDAN CON LA FECHA DE LA CELDA
A1 ES DECIR 01/08/2007 LA CUAL TIENE FORMATO DE FECHA 'CONVIRTIENDOLA ANTES
DE LA COMPARACION DE CUALQUIER FORMA
MovBancarios.Open "select * from movimientosbancarios where " & _
" [fecha]=" & CDATE(Cells(1, 1)), Conexion, adOpenDynamic,
dLockOptimistic

SIN EMBAGO NO ME RECUPERA NINGUN REGISTRO AUN Y CUANDO TENGO REGISTROS QUE
COINCIDEN CON ESE CRITERIO DE FECHA.

GRACIAS ANTICIPADAS POR EL APOYO.
 

Leer las respuestas

#1 Maxi
26/11/2007 - 16:27 | Informe spam
Hola, recuerde que SQLServer no tiene un campo tipo fecha, lo que tiene SQL
es un campo tipo datetime donde guarda la fecha y hora.
Entonces si usted usa = no es la forma correcta de que busque las fechas,
aca le paso un ejemplo de como consultar los registro del 1/12/2007

where fecha >='20071201' and fecha < '20071202'

esta query incluira todos los registros que inicien con 1/12/2007 00:00:00
hasta
1/12/2007 23:59


-
Microsoft M.V.P en SQLServer
SQLTotal Consulting - Servicios en SQLServer
Email:
"Edgar Brito" escribió en el mensaje
news:
Si alguien puede ayudarme con esto:

tengo una hoja de excel cuyos datos intento enviar a sql server 2005 asi
que
utilizo ADO de la siguiente forma:

Dim Conexion As ADODB.Connection, CadenaConexion As String
Set Conexion = New ADODB.Connection
'CADENA DE CONEXION
Conexion.Open "Provider=SQLNCLI; " & _
"Initial Catalog=tesoreria; " & _
"Data Source=desktop; " & _
"integrated security=SSPI; persist security info=True;"

Dim MovBancarios As ADODB.Recordset
Set MovBancarios = New ADODB.Recordset
'DEL LADO DEL CLIENTE
MovBancarios.CursorLocation = adUseClient
MovBancarios.CursorType = adKeySet
'TRATO DE RECUPERAR LOS REGISTROS QUE COINCIDAN CON LA FECHA DE LA
CELDA
A1 ES DECIR 01/08/2007 LA CUAL TIENE FORMATO DE FECHA 'CONVIRTIENDOLA
ANTES
DE LA COMPARACION DE CUALQUIER FORMA
MovBancarios.Open "select * from movimientosbancarios where " & _
" [fecha]=" & CDATE(Cells(1, 1)), Conexion, adOpenDynamic,
dLockOptimistic

SIN EMBAGO NO ME RECUPERA NINGUN REGISTRO AUN Y CUANDO TENGO REGISTROS QUE
COINCIDEN CON ESE CRITERIO DE FECHA.

GRACIAS ANTICIPADAS POR EL APOYO.

Preguntas similares