I wanted to update an entire column (January) in my report table. I need a different way to do this. I got this error when running the following:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
IF OBJECT_ID (N'dbo.Temp_ReportData', N'U') IS NOT NULL
DROP TABLE dbo.Temp_ReportData;
Select DISTINCT NAME, started, cnumber, CAST(started AS varchar(20)) AS cmonth,
MONTH(CAST(started AS varchar(20))) as nmonth, 00000000.00 AS JanAmt,
00000000.00 AS FebAmt, 00000000.00 AS MarAmt, 00000000.00 AS AprAmt,
00000000.00 AS MayAmt, 00000000.00 AS JunAmt, 00000000.00 AS JulAmt,
00000000.00 AS AugAmt, 00000000.00 AS SepAmt, 00000000.00 AS OctAmt,
00000000.00 AS NovAmt, 00000000.00 AS DecAmt
INTO dbo.Temp_ReportData
from confern
WHERE started >= CAST( @startingdate AS datetime)
order by 2;
Update .dbo.Temp_ReportData
SET JanAmt = JanAmt +
(Select cost FROM dbo.Temp_Detailstable
WHERE dbo.Temp_Detailstable.Cnumber = Temp_reportData.cnumber AND MONTH(CAST(dbo.Temp_Detailstable.dateentered AS varchar(20)))=1 AND
(dbo.Temp_Detailstable.Type='Registration' OR (dbo.Temp_Detailstable.Type = 'Discount' AND dbo.Temp_Detailstable.Item like 'UBS') OR dbo.Temp_Detailstable.Type='Credit') );
GO
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
IF OBJECT_ID (N'dbo.Temp_ReportData', N'U') IS NOT NULL
DROP TABLE dbo.Temp_ReportData;
Select DISTINCT NAME, started, cnumber, CAST(started AS varchar(20)) AS cmonth,
MONTH(CAST(started AS varchar(20))) as nmonth, 00000000.00 AS JanAmt,
00000000.00 AS FebAmt, 00000000.00 AS MarAmt, 00000000.00 AS AprAmt,
00000000.00 AS MayAmt, 00000000.00 AS JunAmt, 00000000.00 AS JulAmt,
00000000.00 AS AugAmt, 00000000.00 AS SepAmt, 00000000.00 AS OctAmt,
00000000.00 AS NovAmt, 00000000.00 AS DecAmt
INTO dbo.Temp_ReportData
from confern
WHERE started >= CAST( @startingdate AS datetime)
order by 2;
Update .dbo.Temp_ReportData
SET JanAmt = JanAmt +
(Select cost FROM dbo.Temp_Detailstable
WHERE dbo.Temp_Detailstable.Cnumber = Temp_reportData.cnumber AND MONTH(CAST(dbo.Temp_Detailstable.dateentered AS varchar(20)))=1 AND
(dbo.Temp_Detailstable.Type='Registration' OR (dbo.Temp_Detailstable.Type = 'Discount' AND dbo.Temp_Detailstable.Item like 'UBS') OR dbo.Temp_Detailstable.Type='Credit') );
GO