Hi,
I am getting erorr sql stored procedure
Code
Select ProductID,ProductName,ProductCategoryName,Sum(UnitsInStock),ProductImageID,SUBSTRING(Description,1,150) + '...' As Description,Price,DeliveryDate from Products INNER JOIN ProductCategory ON ProductCategory.ProductCategoryID = Products.ProductCategoryID
Error Message
Msg 8120, Level 16, State 1, Line 1
Column 'Products.ProductID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
How to fix this ?
Loading
Manish DwivediPosted Jan 20, 2011, 1:55 AM
you have used the aggregate function SUM in the select, so you have to use Group By clause for each selected column like that
Select ProductID,ProductName,ProductCategoryName,Sum(UnitsInStock),ProductImageID,SUBSTRING(Description,1,150) + '...' As Description,Price,DeliveryDate from Products INNER JOIN ProductCategory ON ProductCategory.ProductCategoryID = Products.ProductCategoryID group by ProductID,ProductName,ProductCategoryName,ProductImageID,Description,Price,DeliveryDate
by this way you can remove this error.
Krishna GaradPosted Jan 20, 2011, 1:07 AM