---
title: "Fel på sql (script timeout)"
type: "forum-thread"
url: "https://www.webforum.nu/amne/databaser-sql/111548-fel-på-sql-script-timeout"
topic: "Databaser & SQL"
topic_url: "https://www.webforum.nu/amne/databaser-sql"
author: "jimpa"
published: "2004-09-14T16:21:00.000Z"
updated: "2004-09-15T14:57:01.000Z"
replies: 6
views: 596
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/databaser-sql/111548-fel-på-sql-script-timeout"
---

# Fel på sql (script timeout)

## #1 — jimpa, 2004-09-14T16:21Z

Hej,
Jag försöker plocka ut den senaste posten is tabellen "replies" samt User id och User namn i tabellen "Users"
Problemet är att när jag öppnar sidan står den bara o tuggar o tuggar till jag får script.timeout!?

sql´n

```
 SQL = "SELECT TOP 1 Threads.ThreadID, "
    SQL = SQL & "Replies.ReplyID, Replies.rDate, "
    SQL = SQL & "Users.userID, Users.uName "
    SQL = SQL & "FROM "
    SQL = SQL & "(((Forums "
    SQL = SQL & "INNER JOIN Threads "
    SQL = SQL & "ON Forums.ForumID = Threads.tForumID) "
    SQL = SQL & "INNER JOIN Replies "
    SQL = SQL & "ON Threads.ThreadID = Replies.rThreadID) "
    SQL = SQL & "INNER JOIN Users "
    SQL = SQL & "ON Replies.rUserID = Users.UserID) "
    SQL = SQL & "WHERE Forums.fGroupID = " & objRS("GroupID") & " "
    SQL = SQL & "ORDER BY Replies.rDate DESC"
    Set RS = Conn.Execute(SQL)
```

Med response.write får jag

```
SELECT TOP 1 Threads.ThreadID, Replies.ReplyID, Replies.rDate, Users.userID, Users.uName FROM (((Forums INNER JOIN Threads ON Forums.ForumID = Threads.tForumID) INNER JOIN Replies ON Threads.ThreadID = Replies.rThreadID) INNER JOIN Users ON Replies.rUserID = Users.UserID) WHERE Forums.fGroupID = 1 ORDER BY Replies.rDate DESC
```

Vad gör jag för fel?

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

## #2 — yohpops, 2004-09-14T17:21Z

Prova att ta bort parenteserna runt joinarna, och ev. ändra asp scripttimeout.
Den brukar vara satt till 90 sek eller dylikt.

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

## #3 — LarsG, 2004-09-14T17:28Z

Parenteserna behövs om man använder access.

Indexering!

Dela upp frågan i mindre delar och se vad som tar tid.

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

## #4 — jimpa, 2004-09-14T17:47Z

Nu har jag provat att tabort all joinarna utom en men det blir ingen skillnad?
Kolla den här sql

```
strSQL = "SELECT Groups.GroupID, Groups.gName, Groups.gActive, Groups.gOrder, Groups.gDescription, "
strSQL = strSQL & "(select Count(*) from Forums where fActive = true and fGroupID = Groups.GroupID) as cForum, "
strSQL = strSQL & "Forums.ForumID, "
strSQL = strSQL & "(select Count(Threads.ThreadID) from (Forums left join Threads on Forums.ForumID = Threads.tForumID) where Forums.fGroupID = Groups.GroupID) as cThread, "
strSQL = strSQL & "(select Count(Replies.ReplyID) from ((Forums left join Threads on Forums.ForumID = Threads.tForumID) left join Replies on Threads.ThreadID = Replies.rThreadID) where Forums.fGroupID = Groups.GroupID) as cReplies, "
[b]'strSQL = strSQL & "(select top 1 Replies.ReplyID from ((Forums inner join Threads on Forums.ForumID = Threads.tForumID) left join Replies on Threads.ThreadID = Replies.rThreadID) where Forums.fGroupID = Groups.GroupID order by Replies.rDate desc) as lastReplyID, "[/b]
strSQL = strSQL & "Threads.ThreadID, Threads.tUserID, Threads.tDate, "
strSQL = strSQL & "Users.UserID, Users.uName "
strSQL = strSQL & "FROM (((Groups "
strSQL = strSQL & "LEFT JOIN Forums "
strSQL = strSQL & "ON Groups.GroupID = Forums.fGroupID) "
strSQL = strSQL & "LEFT JOIN Threads "
strSQL = strSQL & "ON Forums.ForumID = Threads.tForumID) "
strSQL = strSQL & "LEFT JOIN Users "
strSQL = strSQL & "ON Threads.tUserID = Users.UserID) "
strSQL = strSQL & "WHERE Groups.gActive = true AND Forums.fActive = true "
strSQL = strSQL & "ORDER BY Groups.gOrder DESC, Threads.tDate DESC"
Set objRS = Conn.Execute(strSQL)
```

 
Den funkar om jag tarbort den fetmarkerade raden. Men med den försöker jag hämta "ReplyID" för den senaste posten i tabellen "Replies". Fattar inte vad som går fel?

Det jag helst skulle villja få fram med den är den senaste posten i tabellerna "Threads" eller "Replies" tillsammans med resp. user ID, User name. Som det är nu måste jag hämta den infomationen i själva loopen sedan med en separat sql-sats :( Men i detta fallet finns det väl inga alternativ(?)

Någon?

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

## #5 — jimpa, 2004-09-15T12:59Z

Ingen som har något tipps?

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

## #6 — danjel, 2004-09-15T13:06Z

"order by Replies.rDate desc"...
Är rDate bara datum eller datum och tid ? Då kan order by ta lååång tid..
Hur många rader är det?

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

## #7 — jimpa, 2004-09-15T14:57Z

Det är datum och tid, men databasen är nästan tom så felet måste ligga någon annanstans!

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

---

Tråden på webben: https://www.webforum.nu/amne/databaser-sql/111548-fel-på-sql-script-timeout
