04. juli 2008 - 14:02Der er
15 kommentarer og 2 løsninger
udvælg nyere rækker, med dato og tid i to tekstkolonner
Jeg har en tabel hvor dato er én tekstkolonne, og tid er en anden tekstkolonne. Jeg har hverken mulighed for at samle dem til én kolonne eller lave dem om til datotid.
Nu skal jeg så udvælge rækker der er nye end en bestemt dato og tid, ved hjælp af de to kolonner. Spørgsmålet er hvordan? Naturligvis kan jeg indlæse alle rækker og behandle det derefter, men jeg vil helst select'e mig ud af det, af hensyn til både tid og resourcer.
Nogle der ved hvordan? Eller om det slet ikke kan lade sig gøre?
so something like "select Cdate(textdatefield) as newdate, Cdate(texttimefield) as newtime, * from table where (newdate >= " + laterthandate.tostring + ") and (newtime > " + laterthantime.tostring + ")"
something like that should work, but you can also include the date and time in the same function call.
.. Cdate(textdatefield & ' ' & texttimefield) as DateTimeField
But ther is no guaranty that this will work without alterations. Working with dates is always a problem and when they are in text fields doesnt make it any easier.
hehe working with dates is the ever dreaded task ;)
Anyway, your guaranty of no gauranty was spot on :D
I tried this:
"SELECT COUNT(*) AS amount, CDate(oprettelsesdato & ' ' & oprettelsestidspunkt) as DateTimeOpret, CDate(aendringsdato & ' ' & aendringstidspunkt) as DateTimeRet FROM sagstabel WHERE (DateTimeOpret > #" + lastrundate.ToString + "#) OR (DateTimeRet > #" + lastrundate.ToString + "#)"
and got this error:
"Du har forsøgt at køre en forespørgsel, der ikke medtager det angivne udtryk "CDate(oprettelsesdato & ' ' & oprettelsestidspunkt)" som en del af en aggregatfunktion."
Not sure what that means, anyhow, that made me try this:
"SELECT COUNT(*) AS amount FROM sagstabel WHERE (CDate(oprettelsesdato & ' ' & oprettelsestidspunkt) > #" + lastrundate.ToString + "#) OR (CDate(aendringsdato & ' ' & aendringstidspunkt) > #" + lastrundate.ToString + "#)"
but got this error:
"Datatyperne stemmer ikke overens i kriterieudtrykket."
to which my spontanious response was: "What do you thing I'm trying to work around???" :D
yes I did - I'm trying to figure out how to incorporate it into my system :) The thing is, I'm not supposed to change anything in the source database ;) But it must be possible to use your example somehow anyway. I'll let you know how it works out :)
"..The thing is, I'm not supposed to change anything in the source database ;) ..."
Are you saying that the dB is only for data and your using some other programming language to make the frontend?
You should be able to use the query qryDateTime(I think it was called) as the base for your SQL and incorporate the criteria in that. Then once its working you can copy the SQL into your front-end program. So ther should be no need to alter the Access dB.
That is what I'm saying :) But I did manage to get some steps closer - I think :D
I created a new blank database, created a link to the table in the source database, and then added the qryDateTime query to that new database. Wasn't quite sure if that would work, but it did.
Only thing now is, it keeps saying "Datatyperne stemmer ikke overens i kriterieudtrykket." when trying to use ChangeDateTime in stead of CreateDateTime - can't quite figure out where the difference between them is
SELECT COUNT(*) as amount FROM (qryDateTime) WHERE ((qryDateTime.CreateDateTime) > #" + lastrundate + "#)
works fine, but
SELECT COUNT(*) as amount FROM (qryDateTime) WHERE ((qryDateTime.ChangeDateTime) > #" + lastrundate + "#)
doesn't
SELECT COUNT(*) as amount FROM (qryDateTime) WHERE ((qryDateTime.CreateDateTime) > #" + lastrundate + "#) OR ((qryDateTime.ChangeDateTime) > #" + lastrundate + "#)
and the one that would be needed (both as count and regular select) above neither - in both cases "Datatyperne stemmer ikke overens i kriterieudtrykket" pops up, very weird :D
Does this query help, just tried your scenario: a = date in text form b = time in text form
the where clause defines the date SELECT Table1.a, Table1.b, CDate([a])+CDate([b]) AS c FROM Table1 WHERE (((CDate([a])+CDate([b]))>#1/1/2001 10:10:0#));
In your program try putting the SQL into a string variable and then copy the string into a query directly in Access. This way you can see exactly how the SQL is and more easily find the problem.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.