Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
String sql = "SELECT StockID,Config.ConfigID,ProductName,Features,Price,sum(Quantity) from Stock,Config where Stock.ConfigID=Config.ConfigID group by StockID,productname,Price,Features,Config.ConfigID having sum(quantity > 0) order by ProductName";
Posted

1 solution

Hi,

Try the following:
C#
String sql = "SELECT StockID,Config.ConfigID,ProductName,Features,Price,sum(Quantity) from Stock,Config where Stock.ConfigID=Config.ConfigID group by StockID,productname,Price,Features,Config.ConfigID having (sum(quantity) > 0) order by ProductName";


I modified the bracket surrounding the sum expression.

C#
String sql = "SELECT StockID,Config.ConfigID,ProductName,Features,Price,sum(CONVERT(INT, Quantity)) from Stock,Config where Stock.ConfigID=Config.ConfigID group by StockID,productname,Price,Features,Config.ConfigID having (sum(CONVERT(INT,quantity)) > 0) order by ProductName"





Hope it helps.
 
Share this answer
 
v2
Comments
Member 10720633 20-Jun-14 7:46am    
now error is operand datatype nvarchar is invalid for sum operator
[no name] 20-Jun-14 7:49am    
Are you storing numbers as strings?
Member 10720633 20-Jun-14 7:58am    
no in int
CHill60 20-Jun-14 8:27am    
The only way you would get this error with the SQL you posted would be if the database column Quantity (or quantity) is of type NVarchar - so either you need to change the database column type or you haven't posted the sql that is causing this new error
hypermellow 20-Jun-14 9:17am    
As the other posters have stated, the datatype error is caused by the data type of the quantity column.

I've updated my solution to convert the quantity column to an int, when passing it to the sum function.

Hope it helps.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900