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
 General SQL Server Forums
 New to SQL Server Programming
 Need Help with a bit of a query

Author  Topic 

hjavaher
Starting Member

16 Posts

Posted - 2010-10-15 : 12:19:03
Hi everyone, I am an absolute beginner to SQL and for a project I have to basically access a couple of tables and aggregate the data. I have included the code below and was wondering if you guys can tell me whats wrong with it. I think the SQL Statement (although poorly written) is pretty much self explanatory but let me know if needed an explaination.

Thank you in advance for any help
Jason

SELECT     (dbo.Product.SKU & dbo.ProductVariant.SKUSuffix) as SKU, dbo.ProductVariant.Inventory AS Avaliable, (SELECT sum(dbo.Orders_ShoppingCart.Quantity FROM dbo.Orders_ShoppingCart INNER JOIN dbo.Orders ON dbo.Orders_ShoppingCart.OrderNumber = dbo.Orders.OrderNumber WHERE ((dbo.Orders.ShippingTrackingNumber IS NULL) OR (dbo.Orders.ShippingTrackingNumber = N'')) AND ((dbo.Orders.TransactionState = N'Captured') OR (dbo.Orders.TransactionState = N'Pending')) AND (dbo.Orders_ShoppingCart.VariantID = dbo.ProductVariant.VariantID) Group BY(dbo.Orders_ShoppingCart.VariantID) Order By dbo.Orders_ShoppingCart.VariantID) as Pending
FROM dbo.ProductVariant INNER JOIN
dbo.Product ON dbo.ProductVariant.ProductID = dbo.Product.ProductID

hjavaher
Starting Member

16 Posts

Posted - 2010-10-15 : 12:21:02
Never mind it was a stupid Parenthesis the was missing on the sum :)

Opps :)
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-17 : 02:30:26
it would be better if you can use short aliases instead of repeating the long schema.object name at all the places.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -