Data Connectivity
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Data Connectivity
Message Icon Topic: Error when want retrive data from Database Post Reply Post New Topic
Author Message
angelyin1984
Newbie
Newbie
Avatar

Joined: 08 May 2009
Location: Malaysia
Online Status: Offline
Posts: 30
Quote angelyin1984 Replybullet Topic: Error when want retrive data from Database
    Posted: 11 Mar 2010 at 6:23pm

Helo everybody.......hope someone can help me in this error...... Thanks.

When i connect this to my crystal report 11, the error shown:
 
Failed to retrive data from the database.
Details: 21000:[Microsoft][ODBC SQL Server Driver][SQL Server]Subquery returned more than one value. This is not permitted when the subquery follows =, !=, <, <=, >, >= or when subquery is used as an expression.
[Database vendor code:512]
 
This is the sql i do, i dono how to correct it.....Please advise...thanks
 
-------------------------------------------------------------------------------------------
SELECT     TOP 100 PERCENT *,
(SELECT     f.[Costing sum 1 (WCS16/KOCSU1)]
 FROM          (SELECT     [Item number], [Costing Type], MAX(CostingDate) AS Maxcostingdate
FROM          dbo.FT_KJCF_ProdCosting6
WHERE      ([Item number] = T1.[Item Number]) AND (CostingDate <= T1.[Accounting Date]) AND Division = T1.[Division]
GROUP BY [Item number], [Costing type]
HAVING      ([Costing type] = '3')) x INNER JOIN
dbo.FT_KJCF_ProdCosting6 f ON f.[Item number] = x.[Item number] AND f.CostingDate = x.Maxcostingdate AND
f.[Costing type] = x.[Costing Type]) AS Material_Cost,
(SELECT     f.[Value component B01] + f.[Value component B02] + f.[Value component B03]
FROM          (SELECT     [Item number], [Costing Type], MAX(CostingDate) AS Maxcostingdate
FROM          dbo.FT_KJCF_ProdCosting6
WHERE      ([Item number] = T1.[Item Number]) AND (CostingDate <= T1.[Accounting Date]) AND Division = T1.[Division]
GROUP BY [Item number], [Costing type]
HAVING      ([Costing type] = '3')) x INNER JOIN
dbo.FT_KJCF_ProdCosting6 f ON f.[Item number] = x.[Item number] AND f.CostingDate = x.Maxcostingdate AND 
f.[Costing type] = x.[Costing Type]) AS Labor_Cost,
 (SELECT     f.[Value component B04] + f.[Value component B05] + f.[Value component B06] + f.[Value component B07] + f.[Value component B08] + f.[Value component B09]
 + f.[Value component B10] + f.[Value component B11] + f.[Value component B12]
FROM   (SELECT     [Item number], [Costing Type], MAX(CostingDate) AS Maxcostingdate
FROM          dbo.FT_KJCF_ProdCosting6
WHERE      ([Item number] = T1.[Item Number]) AND (CostingDate <= T1.[Accounting Date]) AND Division = T1.[Division]
 GROUP BY [Item number], [Costing type]
 HAVING      ([Costing type] = '3')) x INNER JOIN
  dbo.FT_KJCF_ProdCosting6 f ON f.[Item number] = x.[Item number] AND f.CostingDate = x.Maxcostingdate AND
f.[Costing type] = x.[Costing Type]) AS OverHead_Cost
FROM         dbo.FT_KJCF_GP_Margin T1
ORDER BY Division, [Item number]
 
----------------------------------------------------------------------------------------
 
 
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 12 Mar 2010 at 7:26am
Looks like a pretty complicated SQL statement and you are getting an SQL error.  I would post this question at SQLServerCentral.com.  They are really good with SQL.
IP IP Logged
kevlray
Admin Group
Admin Group
Avatar

Joined: 29 Oct 2009
Online Status: Offline
Posts: 1587
Quote kevlray Replybullet Posted: 12 Mar 2010 at 11:00am
I had some spare time and I was looking at the query.  I cannot say it would cause a problem since I have not done much with nested select statments, but you have the same alias for three of the select statements (x).  I think this would be an issue.
IP IP Logged
angelyin1984
Newbie
Newbie
Avatar

Joined: 08 May 2009
Location: Malaysia
Online Status: Offline
Posts: 30
Quote angelyin1984 Replybullet Posted: 14 Mar 2010 at 11:33pm
kevlray......thanks for your help!Smile
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.016 seconds.