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

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Qty times total in query

Author  Topic 

taunt
Posting Yak Master

128 Posts

Posted - 2013-03-20 : 15:53:05
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.

Thanks

chadmat
The Chadinator

1974 Posts

Posted - 2013-03-20 : 16:01:19
Are there rows that have NULL value for Quantity? If so, put ISNULL(Quantity,0)

-Chad
Go to Top of Page

taunt
Posting Yak Master

128 Posts

Posted - 2013-03-20 : 16:01:28
Arg! nevermind I got it to work using SalesH.Cost*SUM(SalesH.Quantity)
Go to Top of Page
   

- Advertisement -