home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.databases.ms-sqlserver      Notorious Rube Goldberg contraption      19,505 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 17,902 of 19,505   
   Erland Sommarskog to TEKJunky   
   Re: An aggregate may not appear in the W   
   02 Sep 10 23:26:44   
   
   2c2f9bf4   
   From: esquel@sommarskog.se   
      
   TEKJunky (atl.ryan@gmail.com) writes:   
   > I am a novice at SQL and cannot figure out an effective way to export   
   > a product file that only has products over 25% margin.   
   >...   
   > AND (pe.ProductPrice > 0 AND pe.ProductPrice IS NOT NULL)   
   > AND (SUM(pe.Vendor_Price/pe.ProductPrice) > '.25')   
      
   In addition to Bob's comment, a few observations:   
      
   o  The number should not be in quotes.   
      
   o  The expressions should probably be   
      "pe.ProductPrice/pe.Vendor_price > 1.25". What you have cannot be   
      correct. Assume for instance that vendor price = product price...   
      
   o  To avoid division by zero you need this:   
      
      pe.Vendor_Price / nullif(pe.ProductPrice, 0)   
      
      The condition pe.ProductPrice > 0 is not enough, because there is   
      no guarantee in which order SQL Server evaluates the expressions.   
      
      
   --   
   Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se   
      
   Links for SQL Server Books Online:   
   SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx   
   SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx   
   SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca