Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Adding a CASE WHEN in a WHERE clause
Message
De
30/07/2015 09:07:44
 
 
À
29/07/2015 16:49:54
Walter Meester
HoogkarspelPays-Bas
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:
01622652
Message ID:
01622687
Vues:
30
>Consider the following. By no means error free, as I cannot test, but to give you an idea.
>
>>>
>UPDATE Client
>	SET DayBetweenFirstAcceptSoldDate = ISNULL(Seconds,0)
>	FROM Client
>		LEFT JOIN (SELECT SUM(CASE WHEN ... THEN ... ELSE ... END  ) as seconds, ClientID as clientid2
>                                 FROM Client 
>					LEFT JOIN Company ON Company.NoCountry=1 AND Company.Numero=Client.NoCompany
>					LEFT JOIN Research ON Research.NoCountry=1 AND Research.Numero=Client.NoResearch
>					LEFT JOIN BusinessTime ON BusinessTime.NoProvince = COALESCE(Company.NoProvince, Research.NoProvince, 84) AND 
>											BusinessTime.NoHoliday=0 AND
>											BusinessTime.Start<Client.QueryDate AND
>											BusinessTime.[End]>=Client.FirstAcceptDate
>				WHERE 	Client.FirstAcceptDate>'1899-12-30 00:00:00.000' AND
>						Client.QueryDate>'1899-12-30 00:00:00.000' AND
>						Client.QueryDate>=Client.FirstAcceptDate AND
>						(Client.NoCompany>0 OR Client.NoResearch>0)
>				GROUP BY ClientID)  as Temp ON ClientId = ClientID2
>
>
>
>You can run the subquery as a separate SELECT to check whether it produces the right results

Thanks
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
Répondre
Fil
Voir

Click here to load this message in the networking platform