🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #784

Re: Subquery problem

#784
From: Bill Todd
Date: Mon, 16 Jul 2007 12:38
28 lines
1648 bytes
I suspect that what you want is something like the following. You
cannot used the same table reference in both the main query and the
subquery.

SELECT
DOCLINE.DOCLINE_ID,
DOCLINE.ITEM_ID,
DOCLINE.DOCLINE_QTY,
DOCLINE.DOCLINE_TOTAL_VALUE,
(
SELECT SUM( DL.DOCLINE_TOTAL_VALUE ) FROM DOC DC
INNER JOIN DOCLINE DL ON (DC.DOC_ID = DL.DOC_ID)
WHERE
(DC.DOC_ID < :DOC_ID) AND (DL.ITEM_ID = DOCLINE.ITEM_ID) AND
(DC.PROJ_ID = :PROJ_ID)
)
AS PREVIOUSLY_INVOICED,
DOCLINE.LOC_NAME

FROM LOC
 RIGHT OUTER JOIN ITEM ON (LOC.LOC_ID = ITEM.LOC_ID)
 INNER JOIN DOCLINE ON (ITEM.ITEM_ID = DOCLINE.ITEM_ID)

WHERE
DOCLINE.DOC_ID = :DOC_ID

-- 
Bill Todd (TeamB)
Technical Details
Message-ID: <469b66df$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <469b535e$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,4f66c113f8146a2e
X-Google-Attributes: gid114a0e,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Bill Todd" <no@no.com>
Subject: Re: Subquery problem
Newsgroups: borland.public.interbase.sql
References: <469b535e$1@newsgroups.borland.com>
Organization: The Database Group, Inc.
User-Agent: XanaNews/1.18.1.6
X-Face: ":yn4zt^A_dn>6~{YJmu^B\'4w)e:apPM\VC=Dvf&*tASxX9|BYczkFd$xr.$vNSZ[3Uobr p]c4\+\l){!WQI.$]veP({HLd;CDYH?iN
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
NNTP-Posting-Host: 216.207.211.19
Message-ID: <469b66df$1@newsgroups.borland.com>
Date: 16 Jul 2007 05:38:55 -0700
X-Trace: newsgroups.borland.com 1184589535 216.207.211.19 (16 Jul 2007 05:38:55 -0700)
Lines: 28
X-Authenticated-User: btodd
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail