Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fourgeotf/bb2884e392899b4ac8af6539f3463b8c to your computer and use it in GitHub Desktop.
Save fourgeotf/bb2884e392899b4ac8af6539f3463b8c to your computer and use it in GitHub Desktop.
[Mise en sommeil des clients créés depuis plus de 5 ans sans documents] #loisiralp #sql
--SELECT
-- ct.CT_Num
-- ,ct.cbCreation
-- ,ct.CT_NumPayeur
-- ,do.Max_DO_Date
-- ,ct.CT_Sommeil
UPDATE ct SET ct.CT_Sommeil = 1
FROM F_COMPTET ct
LEFT JOIN (SELECT do.DO_Tiers, MAX(do.DO_Date) AS Max_DO_Date FROM F_DOCENTETE do WHERE do.DO_Domaine = 0 GROUP BY do.DO_Tiers) AS do ON do.DO_Tiers = ct.CT_NumPayeur
WHERE YEAR(ct.cbCreation) <= 2017
AND ct.CT_Type = 0
AND ct.CT_Sommeil = 0
AND Max_DO_Date IS NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment