-2

i code query on SQL Server 2019. I have problem about Lead & Lag on SQL Server 2008. Here my query.

SELECT
  DAT_PASIEN,
  REG_KUNJUNGANPASIEN,
  TGL_REGISTRASI,
  LEAD(TGL_REGISTRASI) OVER (ORDER BY TGL_REGISTRASI DESC) NEXT_TGL_REGISTRASI,
  LAG(TGL_REGISTRASI) OVER (ORDER BY TGL_REGISTRASI DESC) PREVIOUS_TGL_REGISTRASI,
  TGL_DISCHARGE
FROM
  REG_KUNJUNGANPASIEN 
WHERE
  DAT_PASIEN = '00000005'
ORDER BY 
  TGL_REGISTRASI DESC

here i add dump sql on my google drive dumpSQL

my result on SQL Server 2019 Result

  • 1
    Why are you still using SQL Server 2008? It's out of support... – Dai Aug 12 '23 at 22:29
  • @Dai my client doesn't want to update SQL Server to a newer version – Fajar Donny Bachtiar Aug 12 '23 at 22:50
  • which problem exactly do you have, windo function where introduced with sql server 2005 so basically they should work – nbk Aug 12 '23 at 23:06
  • 3
    `LAG` and `LEAD` require SQL Server 2012+ - on previous versions you can self join on row number +/- 1 https://stackoverflow.com/a/8673125/73226 - but more tedious to write and not as efficient – Martin Smith Aug 12 '23 at 23:21
  • 3
    @FajarDonnyBachtiar Fire your client. SQL Server Express 2022 doesn’t cost anything and runs fine on decades-old hardware. There is no excuse for running a business on insecure, unsupported systems like this. – Dai Aug 13 '23 at 00:21

0 Answers0