titans4771
MIS
I am getting the below error:
An aggregate may not appear in the set list of an UPDATE statement.
When trying to do this:
UPDATE t
SET [StaffServPay] = SUM(case when d.paycodeid = 1 and computeonunits = 1 then (d.actualunits*d.payrate)
when d.paycodeid = 1 then ISNULL(d.payrate,0) ELSE 0 end),
[CheckPay] = SUM(case when c.paycodeid = 1 and computeonunits = 1 then (c.actualunits*c.payrate)
when c.paycodeid = 1 then c.payrate ELSE 0 end),
[StaffServBill] = SUM(case when d.paycodeid = 1 and computeonunits = 1 then (d.billunits*d.billrate)
when d.paycodeid = 1 then ISNULL(d.billrate,0) ELSE 0 end),
[StaffServOTPay] = SUM(case when d.paycodeid = 2 and computeonunits = 1 then (d.actualunits*d.payrate)
when d.paycodeid =2 then ISNULL(d.payrate,0) ELSE 0 end),
[CheckOT] = SUM(case when c.paycodeid = 2 and computeonunits = 1 then (c.actualunits*c.payrate)
when c.paycodeid = 2 then c.payrate ELSE 0 end),
[StaffServSalaryPay] = SUM(case when d.paycodeid = 7 and computeonunits = 1 then (d.actualunits*d.payrate)
when d.paycodeid = 7 then d.payrate ELSE 0 end),
[StaffServSalaryBill] = SUM(case when d.paycodeid = 7 and computeonunits = 1 then (d.billunits*d.billrate)
when d.paycodeid = 7 then d.billrate ELSE 0 end),
[StaffServExpPay] = SUM(case when s.expenseflag = 1 and computeonunits = 1 then (d.actualunits*d.payrate)
when s.expenseflag = 1 then d.payrate ELSE 0 end),
[StaffServExpBill] = SUM(case when s.expenseflag = 1 and computeonunits = 1 then (d.billunits*d.billrate)
when s.expenseflag = 1 then d.billrate ELSE 0 end),
FROM @TimeCardInfo t
LEFT OUTER JOIN integrateprod.dbo.intxref i3 ON i3.intid = t.intid and i3.fieldid = 477 and i.subscriberid = 3
LEFT OUTER JOIN ss_htrnj.dbo.vw_tcheaderall t on t.tcid = i3.extid
LEFT OUTER JOIN ss_htrnj.dbo.vw_tcdetailall d (NOLOCK) on d.tcid = t.tcid
LEFT OUTER JOIN ss_htrnj.dbo.prchecktc c (NOLOCK) on c.tcdetailid = d.tcdetailid
LEFT OUTER JOIN ss_htrnj.dbo.syspaycodes s (NOLOCK) on s.paycodeid = d.paycodeid
Please advise how to update a table column with aggregate values?
Thanks,
An aggregate may not appear in the set list of an UPDATE statement.
When trying to do this:
UPDATE t
SET [StaffServPay] = SUM(case when d.paycodeid = 1 and computeonunits = 1 then (d.actualunits*d.payrate)
when d.paycodeid = 1 then ISNULL(d.payrate,0) ELSE 0 end),
[CheckPay] = SUM(case when c.paycodeid = 1 and computeonunits = 1 then (c.actualunits*c.payrate)
when c.paycodeid = 1 then c.payrate ELSE 0 end),
[StaffServBill] = SUM(case when d.paycodeid = 1 and computeonunits = 1 then (d.billunits*d.billrate)
when d.paycodeid = 1 then ISNULL(d.billrate,0) ELSE 0 end),
[StaffServOTPay] = SUM(case when d.paycodeid = 2 and computeonunits = 1 then (d.actualunits*d.payrate)
when d.paycodeid =2 then ISNULL(d.payrate,0) ELSE 0 end),
[CheckOT] = SUM(case when c.paycodeid = 2 and computeonunits = 1 then (c.actualunits*c.payrate)
when c.paycodeid = 2 then c.payrate ELSE 0 end),
[StaffServSalaryPay] = SUM(case when d.paycodeid = 7 and computeonunits = 1 then (d.actualunits*d.payrate)
when d.paycodeid = 7 then d.payrate ELSE 0 end),
[StaffServSalaryBill] = SUM(case when d.paycodeid = 7 and computeonunits = 1 then (d.billunits*d.billrate)
when d.paycodeid = 7 then d.billrate ELSE 0 end),
[StaffServExpPay] = SUM(case when s.expenseflag = 1 and computeonunits = 1 then (d.actualunits*d.payrate)
when s.expenseflag = 1 then d.payrate ELSE 0 end),
[StaffServExpBill] = SUM(case when s.expenseflag = 1 and computeonunits = 1 then (d.billunits*d.billrate)
when s.expenseflag = 1 then d.billrate ELSE 0 end),
FROM @TimeCardInfo t
LEFT OUTER JOIN integrateprod.dbo.intxref i3 ON i3.intid = t.intid and i3.fieldid = 477 and i.subscriberid = 3
LEFT OUTER JOIN ss_htrnj.dbo.vw_tcheaderall t on t.tcid = i3.extid
LEFT OUTER JOIN ss_htrnj.dbo.vw_tcdetailall d (NOLOCK) on d.tcid = t.tcid
LEFT OUTER JOIN ss_htrnj.dbo.prchecktc c (NOLOCK) on c.tcdetailid = d.tcdetailid
LEFT OUTER JOIN ss_htrnj.dbo.syspaycodes s (NOLOCK) on s.paycodeid = d.paycodeid
Please advise how to update a table column with aggregate values?
Thanks,