How to select columns with aggregate sql server function

I need to select two columns. calculate the sum of one column and display the 2.display column as is. so I tried under the code

SELECT Sum(CONVERT(FLOAT, Replace(total, Char(0), ''))) AS Total, 
       [product name] 
FROM   tb_sales_entry_each_product 
GROUP  BY [sales date] 

error message

Column 'tb_sales_entry_each_product.Product Name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

where i made error.thanks

+4
source share
2 answers

just need to group

select SUM(CONVERT(float, REPLACE(Total, CHAR(0), ''))) as Total, [Product Name]  
from tb_sales_entry_each_product group by [Sales Date], [product name]

When you make a digital invoice amount, etc., any other columns should be grouped. it's all your missing

+1
source

Try the following:

select SUM(CONVERT(float, REPLACE(Total, CHAR(0), ''))) as Total, 
[Product Name]  ,[Sales Date]
from tb_sales_entry_each_product 
group by [Sales Date],[Product Name]
+1
source

All Articles