Print Page | Close Window

Error when want retrive data from Database

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2022
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=9367
Printed Date: 03 May 2025 at 2:15am


Topic: Error when want retrive data from Database
Posted By: angelyin1984
Subject: Error when want retrive data from Database
Date 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]
 
----------------------------------------------------------------------------------------
 
 



Replies:
Posted By: kevlray
Date 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.


Posted By: kevlray
Date 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.


Posted By: angelyin1984
Date Posted: 14 Mar 2010 at 11:33pm
http://www.crystalreportsbook.com/forum/member_profile.asp?PF=8671&FID=6 - kevlray ......thanks for your help!Smile



Print Page | Close Window