Avatar billede cogitans Nybegynder
03. april 2003 - 11:32 Der er 15 kommentarer og
1 løsning

En SELECT

Jeg har en tabel, der ser således ud:

OpInitialer - Text
Patientnr - Text
Operationsdato - Text
Year - Number
Ugevagtnr - Number
Ugedag - Text
Stuenr - Number
Operationsnr - Number
OpTypegruppenr - Number
Akutoversigtnr - Number

Ud fra den tabel er jeg kun interesseret i antal af de forskellige Operationsnr - som der er 4 forskellige af (1, 2, 3, 4). Det har jeg prøvet af gøre med følgende SQL:

SELECT Operationsnr, Patientnr FROM Operationsstuer WHERE Operationsdato>='0401' AND Operationsdato<='0401' AND (((Operationsstuer.Patientnr)Is Not Null));

Men Access giver hele tiden et forkert svar...og desuden kun 1 svar - altså ikke alle de records, som det var meningen, at den skulle komme med. Hvad gøre jeg forkert, og hvordan skal jeg så gøre?
Avatar billede jkrons Professor
03. april 2003 - 11:37 #1
Operationsdato>='0401' AND Operationsdato<='0401'  er meningsløs. Hvor spørg om den samme betingelse to gange. Hvis daoen skulle have været forskellig, skal du rette And til Or.
Avatar billede -mundi- Nybegynder
03. april 2003 - 11:38 #2
Operationsdato>='0401' AND Operationsdato<='0401'  er det samme som at skrive
Operationsdato='0401' hvad er det helt precist du vil have ud af den query ?
Avatar billede jkrons Professor
03. april 2003 - 11:38 #3
Og jeg vrøvler. AND er rigtig nok, men datoerne skal være forskellige.
03. april 2003 - 11:44 #4
Der er i hvert fald noget helt galt med din SQL.

Du skriver at Operationsdato både skal være >= og <= '0401' Dette gælder kun for lige præcis '0401'. Derfor får du kun 1 post.

Men jeg forstår heller ikke præcist hvad du ønkser.
Kan du uddybe?
Avatar billede -mundi- Nybegynder
03. april 2003 - 11:53 #5
nogen der har tid til at kigge her http://www.eksperten.dk/spm/336788 , jeg sidder lidt fast nemlig :-(
Avatar billede cogitans Nybegynder
03. april 2003 - 12:14 #6
Operationsdato>='0401' AND Operationsdato<='0401' skrev jeg for at debugge SQL'en. Men den fungerede stadigvæk ikke.

Jeg ønsker at få antal udførsler af operationstyper ud vha. sql'en. De forskellige operationstyper er der så 4 af. Så jeg vil gerne have det bestemte antal af hver operationstype indenfor et bestemt tidsrum (derfor startdato & slutdato).?
Avatar billede terry Ekspert
03. april 2003 - 12:27 #7
Maybe I'm not so good at reading Danish, but in your question I dont see ANYTHING concerning Operationsdato but Operationsnr!

SELECT Operationsnr, Patientnr FROM Operationsstuer WHERE Operationsnr in (1,2,3,4) AND Operationsstuer.Patientnr Is Not Null
Avatar billede cogitans Nybegynder
03. april 2003 - 12:31 #8
well, I want to search the table for the number of different Operationsnr in a certain period of time (startdato - slutdato). The numbers in the table can be from 1 to 4. But this is not what I want from my search. I want the number of times the number "1" is figuring in the tabel in that period of time. ANd number of times the number "2" is there....and so on?
Avatar billede terry Ekspert
03. april 2003 - 12:34 #9
You need to make an aggregate(not sure thats spelt correctly) querty.
When the query is in design view press the little button on the menu taht looks like a Z.
Avatar billede terry Ekspert
03. april 2003 - 12:40 #10
There is a row "total" here you will see "Group by". You want to group by Operationsnr but you also want to count how amny there are. So you can select the field again but now in the "total" row choose "Count" from the list.
Now all you need to think about is your date inteval.
Enter SOMETHING like this for the date field criteria
Between #27/03/2003# And #28/03/2003# an dthen in the total field choose "Expression"

and that should do it.
Avatar billede terry Ekspert
03. april 2003 - 12:43 #11
This query will give you the number of each Operationsnr within a given period. You must NOT select Patientnr  and other information as this has NOTHING to do with what you want and will result in the wrong information
Avatar billede cogitans Nybegynder
03. april 2003 - 12:56 #12
well...if there's no Patientnr attached to the record then the operation isn't made. And therefore it shouldn't be counted in the query. So I have to make some kind of check whether patientnr is set or not.
Avatar billede cogitans Nybegynder
03. april 2003 - 13:08 #13
hmm...it doesn't work. When I execute this query:
SELECT Count(Operationsstuer.Operationsnr) AS CountOfOperationsnr
FROM Operationsstuer
HAVING (((Operationsstuer.Operationsdato)>='0301' AND (Operationsstuer.Year)=2003) And ((Operationsstuer.Operationsdato)<='0401' AND (Operationsstuer.Year)=2003));

it results in "0". But the correct answer is 1 of "1" and 3 of "4".
??
Avatar billede terry Ekspert
03. april 2003 - 13:41 #14
WHY dont you have one field containing the date and not a text field for the month+day and a number field for the year?

First try getting the query to work GROUPING on Operationsnr using an aggregate query as I mentioned. Then when you see that works we can look att the date fields etc.

You can also send the db to eksperten@anthell.dk and I will take a look later
Avatar billede cogitans Nybegynder
03. april 2003 - 14:14 #15
Well, now it's working like this:

SELECT Count([Operationsstuer].[Operationsnr]) AS CountOfOperationsnr
FROM Operationsstuer
WHERE (((Operationsstuer.Operationsdato)>='0103' And (Operationsstuer.Operationsdato)<='0104') AND ((Operationsstuer.Operationsnr)=1) AND ((Operationsstuer.Patientnr) Is Not Null));

It was the "count"-thingy that did the job...mostly. So that dude gets the points!
Avatar billede terry Ekspert
03. april 2003 - 14:29 #16
thanks :o)
I can also see that you are now selecting a specific Operationsnr. Well if you use the GROUP BY then you will get the count for each Operationsnr in one go :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