---
title: "varför fel?"
type: "forum-thread"
url: "https://www.webforum.nu/amne/asp/78457-varför-fel"
topic: "ASP"
topic_url: "https://www.webforum.nu/amne/asp"
author: "voigtann1"
published: "2003-05-30T10:29:43.000Z"
updated: "2003-05-30T11:02:19.000Z"
replies: 5
views: 230
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/asp/78457-varför-fel"
---

# varför fel?

## #1 — voigtann1, 2003-05-30T10:29Z

```
SQL = "select 1,count(*) as antal_mess from mess where username = '" & user &"' and read = false union all " &  _
"select 2,count(*) as antal_gb from gb where mott = '" & user &"' and last = false union all " & _
"select 3,count(*) as antal_kompis from kompisar where kompis = '" & user &"' and besvarad = false order by 1"
Set mess = databas.Execute(SQL)
  messantal = mess("antal_mess")
[b]  gbantal = mess("antal_gb")[/b]
  nyakompisar = mess("antal_kompis")
set mess = nothing
```

får felet:
Error Type:
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.
/voigtan/muffel/voigtmuffel/menu.asp, line 9

Permalänk: https://www.webforum.nu/p/78457

## #2 — @nders, 2003-05-30T10:34Z

När du använder Union får du ju inte med några fältnamn från annat än den första queryn.

Resultatet av queryn kommer se ut så här ungefär:

```
          antal_mess
--------  ---------------
1          100
2          200
3          300
```

Mvh

Permalänk: https://www.webforum.nu/p/1067502

## #3 — voigtann1, 2003-05-30T10:50Z

hur ska jag göra då för att få som jag vill?

Permalänk: https://www.webforum.nu/p/1067517

## #4 — @nders, 2003-05-30T10:53Z

movenext

Permalänk: https://www.webforum.nu/p/1067522

## #5 — @nders, 2003-05-30T10:55Z

Eller slå ihop det till en enda query istället för att använda union.

```
SQL = "select count(*) as antal_mess, (select count(*) from gb where mott = '" & user &"' and last = false) as antal_gb, (select count(*) from kompisar where kompis = '" & user &"' and besvarad = false) as antal_kompis from mess where username = '" & user &"' and read = false"
```

Man ska icke krångla i onödan.

mvh

Permalänk: https://www.webforum.nu/p/1067526

## #6 — voigtann1, 2003-05-30T11:02Z

tackar snabel

Permalänk: https://www.webforum.nu/p/1067535

---

Tråden på webben: https://www.webforum.nu/amne/asp/78457-varför-fel
