Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

Permintaan rekursif SQL Server

Lihat menggunakan apa yang disebut CTE (common table expression) (Lihat dokumen MSDN):

;with cteAppointments as (
 select AppointmentID, PersonID, PrevAppointmentID
     from Appointments
     where PrevAppointmentID is null
 union all
 select a.AppointmentID, a.PersonID, a.PrevAppointmentID
     from Appointments a
         inner join cteAppointments c
             on a.PrevAppointmentID = c.AppointmentID
)
select AppointmentID, PrevAppointmentID
    from cteAppointments
    where PersonID = xxx



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Mengonversi file SQL2008 RDL ke SQL2005

  2. Menerapkan Failover di MS SQL Server 2017 Standard

  3. Edit Baris / Catatan Tabel di SQL Server Management Studio ( SSMS) - Tutorial SQL Server / Tutorial TSQL Bagian 18

  4. Ubah format Tanggal menjadi format DD/MMM/YYYY di SQL Server

  5. Mempermudah kinerja SQL Server