Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Simplifying WHERE clause with CASE WHEN
Message
De
21/04/2015 14:29:57
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2012
Application:
Web
Divers
Thread ID:
01618887
Message ID:
01618897
Vues:
36
>Why would not you post the actual UPDATE command (you can disguise column names if you want) and then it will be easier to give you the code. In any case, I don't see why the suggested approach is not going to work. You can always split one command into 2 using CTE (common table expression).
UPDATE Client
 SET DayBetweenFirstDateSecondDate=
  CASE
   WHEN Client.FirstDate>'1899-12-30 00:00:00.000' AND
    Client.SecondDate>'1899-12-30 00:00:00.000' AND
    Client.SecondDate>=Client.FirstDate AND
    Client.NoCompany>0 THEN
    (SELECT COALESCE(SUM(Temp.[Second])/3600.0/8,0)
    FROM (SELECT DATEDIFF(SECOND,
     CASE WHEN BusinessTime.Start>Client.FirstDate THEN BusinessTime.Start ELSE Client.FirstDate END,
     CASE WHEN BusinessTime.[End]<Client.SecondDate THEN BusinessTime.[End] ELSE Client.SecondDate END) AS [Second]
     FROM BusinessTime
     WHERE BusinessTime.NoProvince=
      CASE
       WHEN (SELECT NoCompany.NoCountry FROM NoCompany WHERE NoCompany.Numero=Client.NoCompany)=1 THEN
       (SELECT NoCompany.NoProvince FROM NoCompany WHERE NoCompany.Numero=Client.NoCompany) ELSE 84
      END AND
      BusinessTime.NoHoliday=0 AND
      BusinessTime.Start<Client.SecondDate AND
      BusinessTime.[End]>=Client.FirstDate) Temp)
   ELSE 0
  END
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform