Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Continuation of Message #1594531 - Use of WHERE
Message
De
23/02/2014 09:29:24
 
 
À
22/02/2014 08:58:48
Walter Meester
HoogkarspelPays-Bas
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Application:
Web
Divers
Thread ID:
01594922
Message ID:
01594988
Vues:
46
Do you think that:
   ;WITH POTemp as
      ( SELECT VendorID, SUM(TotalDue) as VendorTotal 
                FROM Purchasing.PurchaseOrderHeader
                WHERE	 where OrderDate BETWEEN '1-1-2008' AND '12-31-2008'  
                  GROUP BY VendorID) 
   
  select Vend.Name,  VendorTotal
    from  Purchasing.Vendor   as Vend
      left outer   join POTemp
               on Vend.BusinessEntityID = POTemp.VendorID
      order by VendorTotal desc
Is more readable than
select Vend.Name, SUM(TotalDue) as VendorTotal
      from  Purchasing.Vendor   as Vend
         left outer  join  Purchasing.PurchaseOrderHeader AS POH  
               on Vend.BusinessEntityID = POH.VendorID AND POH.OrderDate BETWEEN '1-1-2008' AND '12-31-2008'   
         group by Vend.Name   
         order by VendorTotal desc
or
select Vend.Name, (SELECT SUM(TotalDue) FROM   Purchasing.PurchaseOrderHeader 
     WHEREVend.BusinessEntityID = VendorID AND OrderDate BETWEEN '1-1-2008' AND '12-31-2008') as VendorTotal
      from  Purchasing.Vendor   as Vend
      order by VendorTotal desc
?


No. I did not say that they were always more readable. I said that they were often more readable

cannot use two CTE's in one SQL statement.

Huh? I have often used more than one CTE in a single SQL statement.

but to me, simplicity and maintainability is worth much more than to score with a SQL statement that can only be analysed and maintained by high skilled SQL programmers.

Me too. That is why I use them.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform