Avatar billede nyholm Novice
04. november 2005 - 11:13 Der er 4 kommentarer og
1 løsning

Terms in a query

I have a query that looks up a record where the field Arbpassnr IsNull. The records in the table is numbered.
Now I want another query to show the actual record and the record befor and after. Lets say that the field Passnr IsNull in record nbr 34 in the table Resapost. I then want to se nbr 33 to 35 as the result in a query. How do I do that?
The first query is named NullPassnrResapost
Avatar billede fdata Forsker
04. november 2005 - 13:49 #1
One way could be to create a number of queries:

Q_Null holds the Null record
Q_NullPlus1 finds the Null record plus the next
Q_NullMinus1 finds the Null record plus the previous (actually not the Null record as it is already in Q_NullPlus1)
Q_Null_Result joins the two above mentioned

Q_Null
SELECT NullPassnrResapost.Id
FROM NullPassnrResapost
WHERE (((NullPassnrResapost.Arbpassnr) Is Null));


Q_NullPlus1
SELECT TOP 2 NullPassnrResapost.Id, NullPassnrResapost.Arbpassnr
FROM NullPassnrResapost LEFT JOIN Q_Null ON NullPassnrResapost.Id = Q_Null.Id
WHERE (((NullPassnrResapost.Id)>=DLookUp("ID","Q_Null")));


Q_NullMinus1
SELECT TOP 1 NullPassnrResapost.Id, NullPassnrResapost.Arbpassnr
FROM NullPassnrResapost LEFT JOIN Q_Null ON NullPassnrResapost.Id = Q_Null.Id
WHERE (((NullPassnrResapost.Id)<DLookUp("ID","Q_Null")))
ORDER BY NullPassnrResapost.Id DESC;

Q_Null_Result
SELECT * FROM Q_NullPlus1
UNION
SELECT * FROM Q_NullMinus1

Like it?
Avatar billede nyholm Novice
04. november 2005 - 14:52 #2
Looks all fine to my, but how do i use it? Can you give me some guidance?
Avatar billede fdata Forsker
04. november 2005 - 16:30 #3
You are new to Access? Sorry.

1. Create a new query
2. Click OK
3. Do not select any tables or queries - just click Close
4. Select the SQL button or View/SQL ..
5. Paste the code from my answer
6. Save the query under the name above the code

Repeat this for each query
Avatar billede nyholm Novice
04. november 2005 - 16:54 #4
Thanks a lot.
Avatar billede fdata Forsker
04. november 2005 - 18:39 #5
Anytime  ;o)
Avatar billede Ny bruger Nybegynder

Din løsning...

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.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester