Page 1 of 1

Index DateTime

Posted: Sat Nov 07, 2015 8:04 am
by AidTIC
Tengo un Fichero access, y necesito ordenar una tabla por un campo DATETIME.
Hago lo siguiente:

aFichAcc := "DBQ=C:\Fichero.mdb;Driver={Microsoft Access Driver (*.mdb)}"
RDDSETDEFAULT( "SQLMIX" )
IF RDDINFO( RDDI_CONNECT, { "ODBC", aFichAcc } ) == 1
DBUSEAREA( .T.,, "select * from Item", "aITem" )
INDEX ON FIELD->DtAlt TO Actual
ELSE
MSGINFO ("No he Podido Conectar." , "Error de Connexion" )
EndIF

Al ejecutar me dice:
Error SQLMIX/1026 Data Type error


Si modifico :
INDEX ON FIELD->HB_TTOS(DtAlt) TO Actual
Al Compilar me dice:

Error E0030 Syntax error "syntax error at '('"

Alguna Sugerencia??
-------------------------------------------------------------------------------------------------------------------------------------------------------------
I have a file access, and I need to sort a table by a DATETIME field.
I do the following:

aFichAcc := "DBQ=C:\Fichero.mdb;Driver={Microsoft Access Driver (*.mdb)}"
RDDSETDEFAULT( "SQLMIX" )
IF RDDINFO( RDDI_CONNECT, { "ODBC", aFichAcc } ) == 1
DBUSEAREA( .T.,, "select * from Item", "aITem" )
INDEX ON FIELD->DtAlt TO Actual
ELSE
MSGINFO ("No he Podido Conectar." , "Error de Connexion" )
EndIF

When you run it tells me:
SQLMIX Error / 1026 Data Type Error


If I change:
  INDEX ON field-> HB_TTOS (DtAlt) TO Current
When compiling tells me:
   
    E0030 Error Syntax error "syntax error at '('"

Any suggestions??

Re: Index DateTime

Posted: Mon Nov 09, 2015 11:17 am
by vagblad
I don't know if my solution will fit your coding style but that's what i always do when i am not working with pure SQL(MySQL,MS SQL,etc..):

1)Load all the data into an array with AAdd()
2)Sort the array with ASort()
3)Display data

So in your case if the datetime field goes into your array(with name aData) at let's say position[5] you could do :

Code: Select all

ASort(aData,,,{|x , y| x[5] < y[5] }) for ascending
ASort(aData,,,{|x , y| x[5] > y[5] }) for descending
So now you have all your data sorted the way you want and you can display - edit - search at your will.

Hope it helps

Best Regards

Google Translate
-------------------------------------------------------------------------
No sé si mi solución se ajuste a su estilo de codificación , pero eso es lo que siempre hago cuando no estoy trabajando con pura SQL ( MySQL , MS SQL , etc .. ) :

1 ) Coloque todos los datos en una matriz con AAdd ()
2 ) Clasificar la matriz con ASort()
3 ) los datos de visualización

Así que en su caso si el campo de fecha y hora entra en su conjunto (con nombre aData ) a digamos posición [ 5 ] que podía hacer :

Code: Select all

ASort(aData,,,{|x , y| x[5] < y[5] }) para ascendente
ASort(aData,,,{|x , y| x[5] > y[5] }) para descender
Así que ahora usted tiene todos sus datos ordenados de la manera deseada y se puede mostrar - editar - búsqueda en tu voluntad.

Espero eso ayude

Atentamente

Re: Index DateTime

Posted: Mon Nov 09, 2015 11:43 am
by dragancesu
I don't use Access, but indexing sql database is dificult than dbase. You can create index in Access. SQL use index if exist or create temporary, just use ORDER BY somefileld

Re: Index DateTime

Posted: Mon Nov 09, 2015 1:43 pm
by AidTIC
Es que pasar todo a una array para luego ordenarlo, para eso lo tengo como ahora que reviso la tabla entera secuencialmente.

Porque como abririais un .mdb ?

---------------------------------------------------------
It is that it is an Array of call soon, that is why I like now I check the whole table sequentially.

Because as abririais. mdb?

Re: Index DateTime

Posted: Mon Nov 09, 2015 4:49 pm
by andyglezl
Trata con esto...

INDEX ON FIELD->( HB_TTOS(DtAlt) ) TO Actual

ó

INDEX ON FIELD->( HB_TTOS(DtAlt) ) TAG test TO Actual
donde test es el nombre del indice y actual es el nombre del archivo. ( segun mis apuntes de FoxPro).

Re: Index DateTime

Posted: Mon Nov 09, 2015 7:31 pm
by Amarante
Forgive me if I'm wrong, time does not use DBF files, but would not be correct HB_TTOS( Field->DtAlt )?
But also I think the best solution to dragancesu.

Re: Index DateTime

Posted: Thu Nov 12, 2015 3:23 pm
by andyglezl
Hola Amarante

Creo que estas en lo correcto, pero si AidTIC (no sabemos su nombre) no sube un ejemplo y una DB de prueba...

AidTIC, si estas haciendo esto:
DBUSEAREA( .T.,, "select * from Item", "aITem" )
INDEX ON FIELD->DtAlt TO Actual
no necesitas poner FIELD->, a menos que tengas alguna variable con el mismo nombre.
----------------------------------------------------------------------------------------------------------------------------------
Hello Amarante

I think you're right, but if AidTIC (do not know his name) does not raise an example and test DB ...

AidTIC, if you are doing this:
DBUSEAREA (.T. ,, "select * from Item", "aITem")
INDEX ON field->DtAlt TO actual
no need to put field->, unless you have a variable with the same name.

Re: Index DateTime

Posted: Fri Nov 13, 2015 7:40 am
by AidTIC
Muchas gracias a todo, me ha funcionado la opcion de amarante.

Thanks everybody.