Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with sql and sum in a foreach

Status
Not open for further replies.

miguelin

Programmer
Mar 23, 2003
1
ES
Hi...

First, excuse me for my English......

I have a sql in a foreach.... and the sql is this:

select pedido,sum(importe) from tablaejemplo

If this sql has not sum then give an error... but if the sql is this

select pedido,importe from tablaejemplo

then its correct...

what is my problem????

help.... I need him quick
 
Is your importe field a character? If so, you can't use the sum function. You will have to change it to some sort of number field. Dodge20
If it ain't broke, don't fix it.
 
You don't say what the error is but when using sum (and assuming the field is a number) you have to do a group by on the non-aggregated fields in the query. So I think your query should look something like :

select pedido,sum(importe)
from tablaejemplo
group by pedido


Ade
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top