bustercoder
Programmer
- Mar 13, 2007
- 96
Hello, I have this stored proc which selects customers with a 60-day bal who are not on hold which works fine, but now I need to turn this same proc into an update.
I removed the groupings and inserted the update statement as you can see which is commented below, but is this the correct way to do this? Would I still need the group by for the update? All I'm trying to do is update a hold flag from 0 to 1 when customers meet the condition of being over 60-days balance due.
ALTER PROCEDURE [dbo].[not_on_hold_over_60day]
AS
BEGIN
SELECT
RM00101.CUSTNMBR,
RM00101.CUSTNAME,
RM00101.CRLMTAMT,
[Over15Amt] = RM00101.CRLMTAMT * 1.15,
[OVER 60 BALANCE] =
sum(case when RM20101.RMDTYPAL > 6 and datediff(dd, docdate, getdate()) > 60 then -( RM20101.curtrxam)
when RM20101.RMDTYPAL <= 6 and datediff(dd, docdate, getdate()) > 60 then (RM20101.curtrxam)
end),
[BALANCE] =
sum(case when RM20101.RMDTYPAL > 6 then -(RM20101.curtrxam)
when RM20101.RMDTYPAL <= 6 then (RM20101.curtrxam)
end)
FROM
RM20101 WITH (NOLOCK) INNER JOIN
RM00101 WITH (NOLOCK) ON RM20101.CUSTNMBR = RM00101.CUSTNMBR
--UPDATE RM00101 SET hold = 1
WHERE
CRLMTTYP=2 AND HOLD = 0
GROUP BY
RM00101.CUSTNMBR,
RM00101.CUSTNAME,
RM00101.CRLMTAMT
HAVING
sum(case when RM20101.RMDTYPAL > 6 and datediff(dd, docdate, getdate()) > 60 then -( RM20101.curtrxam)
when RM20101.RMDTYPAL <= 6 and datediff(dd, docdate, getdate()) > 60 then (RM20101.curtrxam)
end) > 0 and
sum(case when RM20101.RMDTYPAL > 6 then -(RM20101.curtrxam)
when RM20101.RMDTYPAL <= 6 then (RM20101.curtrxam)
end) > 0
ORDER BY
RM00101.CUSTNMBR
END
GO
Thanks,
Buster
I removed the groupings and inserted the update statement as you can see which is commented below, but is this the correct way to do this? Would I still need the group by for the update? All I'm trying to do is update a hold flag from 0 to 1 when customers meet the condition of being over 60-days balance due.
ALTER PROCEDURE [dbo].[not_on_hold_over_60day]
AS
BEGIN
SELECT
RM00101.CUSTNMBR,
RM00101.CUSTNAME,
RM00101.CRLMTAMT,
[Over15Amt] = RM00101.CRLMTAMT * 1.15,
[OVER 60 BALANCE] =
sum(case when RM20101.RMDTYPAL > 6 and datediff(dd, docdate, getdate()) > 60 then -( RM20101.curtrxam)
when RM20101.RMDTYPAL <= 6 and datediff(dd, docdate, getdate()) > 60 then (RM20101.curtrxam)
end),
[BALANCE] =
sum(case when RM20101.RMDTYPAL > 6 then -(RM20101.curtrxam)
when RM20101.RMDTYPAL <= 6 then (RM20101.curtrxam)
end)
FROM
RM20101 WITH (NOLOCK) INNER JOIN
RM00101 WITH (NOLOCK) ON RM20101.CUSTNMBR = RM00101.CUSTNMBR
--UPDATE RM00101 SET hold = 1
WHERE
CRLMTTYP=2 AND HOLD = 0
GROUP BY
RM00101.CUSTNMBR,
RM00101.CUSTNAME,
RM00101.CRLMTAMT
HAVING
sum(case when RM20101.RMDTYPAL > 6 and datediff(dd, docdate, getdate()) > 60 then -( RM20101.curtrxam)
when RM20101.RMDTYPAL <= 6 and datediff(dd, docdate, getdate()) > 60 then (RM20101.curtrxam)
end) > 0 and
sum(case when RM20101.RMDTYPAL > 6 then -(RM20101.curtrxam)
when RM20101.RMDTYPAL <= 6 then (RM20101.curtrxam)
end) > 0
ORDER BY
RM00101.CUSTNMBR
END
GO
Thanks,
Buster