Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Qty times total in query
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

128 Posts

Posted - 03/20/2013 :  15:53:05  Show Profile  Reply with Quote
Hello here's my query:

SELECT  SalesH.SKU, SalesH.UPC, SalesH.Artist, SalesH.ItemName, SUM(SalesH.Quantity) AS Totalsold, Items.StockQty, SalesH.Attribute2 As format, SalesH.ReleaseDate,  SalesH.Cost*Totalsold as Totalmade
FROM    SalesH inner join Items on SalesH.ItemID = Items.ItemID
WHERE  (SalesH.ReleaseDate = '03/12/2013') AND (SalesH.TDTypeID = 1) AND (SalesH.TID = 1)
GROUP BY SalesH.upc,SalesH.SKU, SalesH.Artist, SalesH.ItemName, SalesH.Attribute2, SalesH.ReleaseDate, Items.StockQty, SalesH.Cost, Totalsold
ORDER BY SalesH.Artist

What I'm trying to do is have sql give me the cost times totalsold (which is SUM(SalesH.Quantity)). So how would I go about wording that so sql understands. Right now it brings up the Totalmade column as null.


The Chadinator

1974 Posts

Posted - 03/20/2013 :  16:01:19  Show Profile  Visit chadmat's Homepage  Reply with Quote
Are there rows that have NULL value for Quantity? If so, put ISNULL(Quantity,0)

Go to Top of Page

Posting Yak Master

128 Posts

Posted - 03/20/2013 :  16:01:28  Show Profile  Reply with Quote
Arg! nevermind I got it to work using SalesH.Cost*SUM(SalesH.Quantity)
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000