Sum() and Count() respect the WHERE clause. Try to rewrite your SELECT-SQL like this:
SELECT Field1, Field2, Field3, Field4, Sum(Field3) AS n_Imp, Count(Field1) AS n_Can;
FROM MyTable;
WHERE (Field2 = tcPeriod) AND (Field3 = tcYear);
INTO CURSOR c_Names;
ORDER BY Field1
Another reason that your code would not give you the result you expect, is if SET ANSI is OFF and tcPeriod and tcYear are empty. In that case, put SET ANSI to ON or use the "==" instead of the single "=".
HTH
>I have this SQL statement.The instruction works fine but it sums and counts all the records.I want to do this but only with filetered records.Is it possible in the same instruction ?
>
>SELECT a.field1, a.field2, a.field3, a.field4 ;
> FROM mytable a ;
> SUM(a.field3) AS n_imp, ;
> COUNT(a.field1) AS n_can ;
> WHERE a.field2 = tcperiod ;
> AND a.field3 = tcyear ;
> ORDER BY a.field1 ;
> INTO CURSOR c_names