Last active
February 8, 2022 09:19
-
-
Save fourgeotf/f7e00def5cf1f32908c21669f315cb25 to your computer and use it in GitHub Desktop.
[Mise en sommeil des clients inactifs depuis 5 ans] #loisiralp #sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE LOISIRALP | |
GO | |
WITH query AS (SELECT | |
ct.CT_Num | |
,ct.CT_Intitule | |
,(SELECT TOP 1 do.DO_Date FROM F_DOCENTETE do WHERE do.DO_Tiers = ct.CT_Num AND DO_Domaine = 0 ORDER BY do.DO_Date DESC) AS DO_Date | |
,(SELECT TOP 1 do.DO_Type FROM F_DOCENTETE do WHERE do.DO_Tiers = ct.CT_Num AND DO_Domaine = 0 ORDER BY do.DO_Date DESC) AS DO_Type | |
FROM F_COMPTET ct | |
WHERE ct.CT_Type = 0) | |
--UPDATE ct SET ct.CT_Sommeil = 1 | |
SELECT | |
ct.CT_Num | |
,ct.CT_Sommeil | |
,DO_Date | |
FROM F_COMPTET ct | |
INNER JOIN query q ON ct.CT_Num = q.CT_Num | |
WHERE YEAR(q.DO_Date) < 2017 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment