I found this syntax already answered to a diff question, but I am getting the error of
More than 1 result returned
what do I need to alter in my syntax in order to defeat this error?
Declare @ONE Table
(
employee varchar(250)
,eod int
)
Declare @Two Table
(
employee varchar(250)
,amtpaid decimal(10,2)
)
Insert Into @One (employee, eod) VALUES
('Frank', '1122')
,('Frank', '1188')
,('Bill', '1100')
,('Larry', '1199')
,('Bill', '2211')
,('Jerry', '3311')
,('Jerry', '3322')
,('Stan', '3388')
,('Stan', '3300')
,('Larry', '3377')
INSERT INTO @Two (employee, amtpaid) VALUES
('Frank', '11.11'),('Bill', '10.10')
,('Larry', '44.44'),('Jerry', '20.32')
,('Stan', '100.33')
SELECT a.employee
,[EOD] = b.eod
,[Paid] = CASE
WHEN b.eod = (
SELECT min(b.eod)
FROM @Two
WHERE b.employee=a.employee
)
THEN COALESCE((
SELECT TOP 1 SUM(ISNULL(amtpaid, 0))
FROM @Two b
WHERE a.employee = b.employee
), 0)
ELSE 0
END
FROM @One b
INNER JOIN @Two a
ON a.employee = b.employee
GROUP BY a.employee, b.eod, b.employee
ORDER BY a.employee ASC
EDIT
My desired output is like below - amtpaid showing for only 1 employeename not all of them
Employee EOD Paid
Bill 1100 10.10
Bill 2211 0.00
Frank 1122 11.11
Frank 1188 0.00
Jerry 3311 20.32
Jerry 3322 0.00
Larry 1199 44.44
Larry 3377 0.00
Stan 3388 0.00
Stan 3300 100.33