1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| WITH AA AS (
SELECT
ROW_NUMBER() OVER(ORDER BY DateUpdate) AS RowId
,[Key]
,[Name]
,[dateUpdate]
,[ISOCC]
FROM [HaPI].[dbo].[Affectation]
WHERE Key='QAR'
), NNN AS (
SELECT
AA.rowid,
AA.Key,
AA.Name,
AA.Dateupdate DA,
BB.Dateupdate DB
FROM AA
INNER JOIN AA BB ON BB.rowid=aa.rowid+1
UNION
SELECT
AA.rowid,
AA.Key,
AA.Name,
AA.Dateupdate DA,
Getdate() DB
FROM AA WHERE aa.rowid=(SELECT MAX(rowid) from aa))
SELECT
c.date_id,
NNN.Name
FROM opdata.dbo.Calendar c
INNER JOIN NNN on c.date_id between NNN.DA and NNN.db |
Partager