Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: Subquery Post Reply Post New Topic
Author Message
Barb
Newbie
Newbie


Joined: 15 Nov 2011
Online Status: Offline
Posts: 29
Quote Barb Replybullet Topic: Subquery
    Posted: 26 Jun 2013 at 10:25am
Hi All
 
I am trying to link a subquery to my main SQL query but amd getting error message re only one expression can be used without EXISTS and about Q2.CC can not be bound.
 
Can you please have a look at the subquery below and let me know where I am going wrong???
 
Any help greatly appriciated.
 
############
SELECT 'JE ' + RTRIM(c.TransId) AS DocNum, c.Line_ID, c.RefDate, c.Account,  c.Debit, c.Credit, c.VatAmount,  c.LineMemo AS RowDescription, c.TransType,  d.Transcode, d.Ref2, d.Memo AS JournalRemarks, d.TaxDate, c.FinncPriod, f.Year, e.SubNum, e.Name, e.F_RefDate, e.T_RefDate, f.F_RefDate as F_YDate, f.T_RefDate as T_YDate, g.AcctName, g.ActType,g.AcctCode, g.FatherNum, g.Levels,g.GrpLine, g.GroupMask, g.AccntntCod,g.FrgnName, h.AcctName AS Father, OADM.CompnyName, OADM.MainCurncy, OADM.SysCurrncy, CC2.OcrCode, CC2.PrcName, (select c.TRansId, MAX(c.ocrCode2) as CC from JDT1 c GROUP BY c.TRansId) Q2
 
From JDT1 c
 
INNER JOIN OJDT d on c.TransId = d.TransId
INNER JOIN OFPR e on e.AbsEntry=c.FinncPriod
INnER JOIN OACP f on f.PeriodCat=e.Category
INNER JOIN OACT g on g.AcctCode=c.Account
INNER JOIN OACT h on h.AcctCode=g.FatherNum
LEFT OUTER JOIN
( SELECT ODIM.DimCode, DimDesc, OOCR.OcrCode, OOCR.OcrName, OPRC.PrcCode, OPRC.PrcName, OCR1.PrcAmount/OCR1.OcrTotal AS Dist, OPRC.CCTypeCode
FROM ODIM
INNER JOIN OOCR ON ODIM.DimCode=OOCR.DimCode
INNER JOIN OCR1 ON OOCR.OcrCode=OCR1.OcrCode
INNER JOIN OPRC ON OPRC.PrcCode = OCR1.PrcCode AND ODIM.DimCode = OPRC.DimCode
WHERE DimActive = 'Y' AND OOCR.Active='Y' AND OPRC.Active='Y') CC2 ON CC2.OcrCode = Q2.CC, OADM
Many thanks
Barb
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 27 Jun 2013 at 4:55am
I think that the issue stems from '(select c.TRansId, MAX(c.ocrCode2) as CC from JDT1 c GROUP BY c.TRansId) Q2'

I don't think that it is legal to define a table this way...especially since SQL thinks that Q2 is the alias for the COLUMN.

If you need to use this value, move it into the FROM clause as JOINED table...inner or outer, and see if that works.

Also, have you tried running select in Query Analyzer so other SQL tool? That would probably help visualize what's going on

HTH
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.