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/f7e00def5cf1f32908c21669f315cb25 to your computer and use it in GitHub Desktop.
Save fourgeotf/f7e00def5cf1f32908c21669f315cb25 to your computer and use it in GitHub Desktop.
[Mise en sommeil des clients inactifs depuis 5 ans] #loisiralp #sql
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