Good morning experts..
request correction for the T-sql coding error below.
it is give me notification that windowed function can be use in select and order clause.
Thank you for your advice and direction.

request correction for the T-sql coding error below.
it is give me notification that windowed function can be use in select and order clause.
Code:
Local lcSQL1, lcSQL2
*norekening = crsSampleData.norekening
norekening = 1111125010021
TEXT TO m.lcSQL1 noshow
create table zonaku (norekening decimal(14), date1 smalldatetime, date2 smalldatetime, payment1 decimal (14))
INSERT INTO zonaku VALUES (1111125010021, CONVERT(VARCHAR, '12/05/2024', 103), CONVERT(VARCHAR, '12/16/2024', 103), 650000)
INSERT INTO zonaku VALUES (1111125010021, CONVERT(VARCHAR, '02/11/2025', 103), CONVERT(VARCHAR, '01/16/2025', 103), 650000)
INSERT INTO zonaku VALUES (1111125010021, CONVERT(VARCHAR, '03/05/2025', 103), CONVERT(VARCHAR, '02/16/2025', 103), 650000)
INSERT INTO zonaku VALUES (1111125010021, CONVERT(VARCHAR, '03/05/2025', 103), CONVERT(VARCHAR, '03/16/2025', 103), 650000)
INSERT INTO zonaku VALUES (1111125010021, CONVERT(VARCHAR, '03/06/2025', 103), CONVERT(VARCHAR, '04/16/2025', 103), 650000)
INSERT INTO zonaku VALUES (1111125010021, CONVERT(VARCHAR, '05/05/2025', 103), CONVERT(VARCHAR, '05/16/2025', 103), 650000)
ENDTEXT
lnResult = SQLExec(Thisform.nHandle, m.lcSQL1)
TEXT TO m.lcSQL2 noshow
select norekening, date1, date2, payment1,
datediff(day,date1, date2) as difference,
datediff(month, date1,date2) as difference1,
MAX(datediff(day, date1, date2)) over(partition by norekening) AS difference2
from dbo.zonaku where norekening = ?m.norekening and
datediff(day,date1, date2) as difference =
MAX(datediff(day, date1, date2)) over(partition by norekening)
group by norekening, date1, date2, payment1
ENDTEXT
lnResult = SQLExec(Thisform.nHandle, m.lcSQL2, 'mutation')
If m.lnResult < 0
Aerror(aWhy)
Messagebox(aWhy[2])
SQLDisconnect(0)
Return .F.
Else
endif
Code:
Thank you for your advice and direction.

