Diffciult query

H

handsomed

I have this query:

SELECT DISTINCT Q.[creation_date], Round(Now()-Q.[creation_date],0) AS
Diferenc,
Q.[Nº Siniest], Q.Asunt, Q.Usu, Q.Obs
FROM [HISTORIC] AS Q
WHERE (((Q.[creation_date])=(SELECT MAX([creation_date])
FROM [HISTORIC] As T
WHERE T.[Nº Siniest] = Q.[Nº Siniest])) AND ((Q.Asunt) Not Like
"Autofact*") AND ((Q.Asunt) Not Like "Final*"))
ORDER BY Q.[creation_date];


[HISTORIC] has this format:

Nº Siniest creation_date Asunt

10408002464 18/11/2008 11:08:00 Repar cur
10408002464 18/11/2008 13:45:00 Pendiente Tramitador
10408002464 19/11/2008 10:15:00 Pendiente Tramitador
10408002464 25/11/2008 17:59:00 Reparaci¢n en curso
10408002464 02/12/2008 14:38:00 Pendiente Tramitador
10408002464 03/12/2008 12:17:00 Pendiente Tramitador
10408002464 05/12/2008 11:55:00 Valoración aceptada
10408002464 05/12/2008 11:55:00 Autofactur

I have a problem in the above case, where the last two rows have the same
creation_date and should take the last row, however it takes the previous row
(10408002464 05/12/2008 11:55:00 Valoración aceptada)

My query must show the row which its [creation_date] is the last of one
[Asunt] and the [Asunt] can't be in the state Autofactur. I mean, I'm trying
to do a list of pending task, and when a [Nº Siniest] is Autofactur it
supposed to be done and it shouldn't be listed.


So, in the example it shouldn't show any rows becouse the [Nº Siniest] is
Autofactur :

10408002464 05/12/2008 11:55:00 Valoración aceptada
10408002464 05/12/2008 11:55:00 Autofactur


But it shows:
10408002464 05/12/2008 11:55:00 Valoración aceptada

Any ideas?
 
C

Connie Brown

Your code includes ((Q.Asunt) Not Like
"Autofact*") which could account for excluding the last line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top